Menu item not active when URL defined for item has a query parameter
Hey guys,
The menu item doesn't get activated when the URL has a query parameter.
Example: $menu->add('Item 1', route('bananas', ['order_by' => 'free']));
On these scenarios, it is never set to active.
Cheers,
Not sure if that's a bug or a feature enhancement.
Seems like support could be added, so just a totally aside thought, but perhaps you could use optional route parameters instead of query strings.
Tried it also with the route paremeters and doesnt work either.
Thanks,
https://github.com/lavary/laravel-menu#named-routes
What did you try? Can you provide some more code of your routes and menu that are not working?
Seems as though it may not set the active class if the current URL is using optional parameters but the link in the menu is not? For example:
// Suppose we have these routes defined in our app/routes.php file
//...
Route::get('/{test?}', ['as' => 'home.page', function(){...}]);
//...
// Now we make the menu:
Menu::make('MyNavBar', function($menu){
$menu->add('Home', ['route' => 'home.page']);
});
So if you visit http://localhost/ then it will get the class but http://localhost/abc will not.
My workaround is:
$class = ($request->routeIs('home.page')) ? 'active' : '';
$menu->add('Home', ['url' => route('home.page'), 'class' => $class]);