vue-router
vue-router copied to clipboard
A redirect with an alias keeps the original url
Version
2.7.0
Reproduction link
http://jsfiddle.net/9r6xhqbp/37/
Steps to reproduce
Add the following to your router:
{
path: '/view',
alias: '/view/*',
redirect: '/analytics',
},
Navigate to /view/blabla.
What is expected?
I'd expect to be redirected to /analytics
What is actually happening?
/view/* is now an alias for /analytics, where I would have expected it to redirect instead.
/view redirects as expected.
Oh and for anyone else experiencing this (unlikely, it seems pretty specific), you can work around it by just adding two entries to your router:
{
path: '/view',
redirect: '/analytics',
},
{
path: '/view/*',
redirect: '/analytics',
},
Callum please, take the time for the repro and instructions 😉
I figured it would be quicker to add that block of code into any existing project using vue-router (and change the value of redirect:) than to clone a git repo and run npm install 😛 will set up a repo now
You don't need a repo for that, use a fiddle: http://jsfiddle.net/posva/9r6xhqbp/
that's easier 😄 added it to the main issue: http://jsfiddle.net/9r6xhqbp/37/
Thanks, as you can imagine, the workaround is to use two routes, one for every redirect
On second thought, this is working as expected, because the point of alias is to keep the original url, so I prefer documenting this and keeping current behaviour which is more flexible
I suppose redirect should take a higher priority here.
User story:
- User navigates to
/view/* - Router finds out
/view/*is an alias and it should keep the original url while following other rules defined under/view - Router finds a
redirectunder/view - Router performs redirection to
/analytics
Since /analytics is totally a different thing from /view, so the expected behavior of the alias(i.e. keep the original url) is out of scope here, hence /analytics in the url bar and $route.path.
ping @posva
~~For that scenario, use multiple redirects but currently, the situation allows to keep the alias, I don't want to remove that~~
Revisiting this, I think it makes more sense for the redirect to take precedence