Is there any way to make route().current() also match params?
See original GitHub issueExpected Behavior
Some way to determine that the route matches, including params. For example, if I’m on any of the following pages, route().current('backend.inventory.show')
returns true because the route name is the same for all:
- /backend/inventory/1/category/2
- /backend/inventory/2/category/2
- /backend/inventory/3/category/13
- /backend/inventory/7/category/1
- /backend/inventory/1/category/13
Current Behavior
I’m not sure if there is already some method or argument to a method that will allow me to determine this.
For bug reports only please provide
Currently installed Laravel version:
5.8.15
Currently installed Ziggy version
0.7.1
Example route from your Laravel Routes file.
Route::get('/backend/inventory/{tenant}/category/{category}', [Backend\InventoryController::class, 'show'])->name('backend.inventory.show');
Contents of Ziggy.namedRoutes
"backend.inventory.show": {
"domain": null,
"methods": [
"GET",
"HEAD"
],
"uri": "backend/inventory/{tenant}/category/{category}"
}
Ziggy call in context
I have a custom Vue directive that uses the href
attribute to determine if the link is to the current page. The link’s href
will be a route: <a :href="route('backend.inventory.show'. { tenant: currentTenant, category: category.id })">{{ category.name }}</a>
export default function (el, binding, vNode) {
let { name } = vNode.data.attrs.href;
if (name === undefined) {
return;
}
// You can ignore this part, it works as intended for those routes that I DO want to be fuzzy matched.
if (binding.modifiers.fuzzy) {
const parts = name.split('.');
if (parts.length > 1) {
parts.splice(-1, 1, '*'); // remove last segment of route and replace with fuzzy token
name = parts.join('.');
}
}
if (route().current(name)) {
el.classList.add('active');
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Match - React Router: Declarative Routing for React.js
A match object contains information about how a <Route path> matched the URL. ... params - (object) Key/value pairs parsed from the URL...
Read more >React router v6 access route params and pass as props
For this you can simply use a wrapper component to "sip" the route match param and pass it along to your component on...
Read more >Dynamic Route Matching with Params - Vue Router
Vue Router uses its own path matching syntax, inspired by the one used by express , so it supports many advanced matching patterns...
Read more >How to Use React Router: useParams | by Megan Lo - Medium
According to the definition in React Router doc, useParams returns: an object of key/value pairs of URL parameters. Use it to access match....
Read more >Use matchPath to Match Nested Route Paths in Parent Routes ...
There may be a time in your application when you need to compare the previous route id to the current route id to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just ran into this myself. It would be awesome if Ziggy handled this out of the box! 👌
I would like to see that
current()
wont return a name but the whole route object, including resolved parametersExample: Route:
/item/{name}
Current url: /item/example So I could usecurrent().parameters
to get:{name: example}