yaminncco / vue-sidebar-menu

A Vue.js Sidebar Menu Component
MIT License
646 stars 194 forks source link

Matching alias against URLs including query params. Version 4 #273

Closed tomastan closed 4 months ago

tomastan commented 4 months ago

Hello,

Unfortunately I'm still stuck with Vue2 in my project, so have to play with version 4.8.1 so far.

I'm having troubles with matching alias URLs which contain query string. For example:

There are group of URLs should be grouped under one menu item: /users/users /users/user?id=1 /users/user?id=*

Trying to use alias and regexp, but it it does not match anyway. Unless alias is set exactly to "/users/user?id=1". exactPath looks to apply to href, but does it ignore alias ?

{
    href: "/users/users",
    title: 'Users',
    exactPath: true,
    alias: ["\/users\/user\?id=[0-9]+", "/users/user"] // Neither works
},

Do I miss something?

yaminncco commented 4 months ago

exactPath match only the pathname /users/user ≠ /users/users so you either change the path or can use alias

{
  href: '/users/users',
  title: 'Users',
  alias: '/users/user?id=(\\d+)'
}
tomastan commented 4 months ago

Thanks, it looks the problem was not in exactPath (which I need to keep for cases like /users/users?query=blablabla ), but with regexp format of alias. Changing it to the shown in your example resolves the issue.

I owe you a coffee!