Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make encoding of params optional #490

Closed
just-tom opened this issue Dec 20, 2021 · 3 comments · Fixed by #500
Closed

Make encoding of params optional #490

just-tom opened this issue Dec 20, 2021 · 3 comments · Fixed by #500
Assignees
Labels

Comments

@just-tom
Copy link

Ziggy version

1.4.2

Laravel version

8.75.0

Description

Hi guys,

In this merge you enabled the encoding of all params and queries by default: #118

This poses a problem when using a route parameter where a forward slash is expected. Laravel can handle this as shown here: https://laravel.com/docs/8.x/routing#parameters-encoded-forward-slashes - but ziggy encodes the url before hand.

Actual result:

  • example.com/mens%2Fblazers

Expected Result:

  • example.com/mens/blazers

Would be great to be able to toggle this behaviour in Ziggy config, maybe discern between route params and query params and be able to toggle either for flexibility

Ziggy call and context

// How I expected to use Ziggy
const goToCategory = (url) => {
  // url = 'mens/blazers'
  Inertia.visit(route('catalog', { slug: url });
}

// How I am working around the issue currently
const goToCategory = (url) => {
  // url = 'mens/blazers'
  const route = decodeURIComponent(route('catalog', { slug: url })
  Inertia.visit(route);
}

Ziggy configuration

{
  "url": "https://local.test",
  "port": null,
  "defaults": {
      "store": "uk"
  },
  routes: {
    "catalog": {
        "uri": "{store}/{slug}",
        "methods": [
            "GET",
            "HEAD"
        ]
    }
  }
}

Route definition

Route::get('/{slug}', [ContentController::class, 'view'])->where('slug', '.*')->name('catalog');

//n.b. the store parameter is added within the RouteServiceProvider as a prefix.
@bakerkretzmar bakerkretzmar self-assigned this Dec 20, 2021
@bakerkretzmar
Copy link
Collaborator

Thanks for the heads up! I think you're right that this should either be configurable or we should automatically do what Laravel does and not encode it if it's the very last route parameter. I'll look into this.

@bakerkretzmar
Copy link
Collaborator

@just-tom I'm coming back to this while digging into #661 and realizing that example.com/mens%2Fblazers and example.com/mens/blazers are actually functionally identical, and both will work exactly the same way with Laravel. Was your issue here that example.com/mens%2Fblazers didn't work correctly? Or just that you wanted / displayed in the URL instead of %2F?

@just-tom
Copy link
Author

@bakerkretzmar wohh blast from the past! hey!

Id I remember correctly it was because i wanted to be able to display the / correctly as mens/blazers without seeing the encoding. e.g. if I stored a customer built "mega menu" in a DB somewhere and that was stored with a path like "mens/blazers" the when building a uri for the path it should accommodate it not encode it using a {{slug}} route

Thats from memory what the issue was to begin with but its been a long while haha!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants