-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Description
Version
3.4.9
Reproduction link
https://jsfiddle.net/jwx6q3hc/4
Steps to reproduce
- Create a router with
{
mode: 'history',
routes: [
{ path: '/a' },
{ path: '/b', beforeEnter: (to, from, next) => next({ name: 'redirect-target' }) },
// { path: '/b', redirect: { name: 'redirect-target' } },
{ name: 'redirect-target', path: '/b' }
]
}
- Initially navigate to
/a
- Navigate to
/b
- Navigate to
/a
- Hit the browser back button
- Hit the browser back button again
What is expected?
After hitting the back button in step 5. we should be back on /a
.
The forward button should be enabled.
The history should look like
/a --- pushed by 3.
/b --- pushed by 2.
/a <-- current, pushed by 1.
What is actually happening?
After hitting back in step 5., we stay on /b
.
The forward button is disabled, browser history looks like this
/b <-- current, pushed by 4.
/a --- pushed by 1.
I hoped this setup would work for a proposal to simplify some dynamic routing in Vue Storefront (take a look at this gist if you're interested in the usecase and some more details). Essentially I want use beforeEnter as a substitute for redirect
where I can do some async requests before returning the redirection target.
The issue here is that calling next
with some redirection arguments is always handled by calling router.push
or router.replace
(in the case of next({ replace: true, ... })
. But in this usecase there should be no change to the browser history during popstate
handling.
Doing the equivalent redirection with redirect
works just fine (though I can't use it for my usecase, as I can't return asynchronously from the redirect function). I've marked this as a bug as from what I understand vuejs/rfcs#150 has the goal that both should work the same way.