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

Menu item not active when URL defined for item has a query parameter #217

Open
gtapps opened this issue May 13, 2018 · 4 comments
Open

Menu item not active when URL defined for item has a query parameter #217

gtapps opened this issue May 13, 2018 · 4 comments

Comments

@gtapps
Copy link

gtapps commented May 13, 2018

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,

@dustingraham
Copy link
Collaborator

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.

@gtapps
Copy link
Author

gtapps commented May 13, 2018

Tried it also with the route paremeters and doesnt work either.

Thanks,

@dustingraham
Copy link
Collaborator

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?

@jeremy-smith-maco
Copy link

jeremy-smith-maco commented Oct 29, 2019

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]);

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

No branches or pull requests

3 participants