Vue-router: How could next(path) act like a replace rather than push

Created on 11 Nov 2016  Â·  7Comments  Â·  Source: vuejs/vue-router

Now I achieve it by next(false),router.replace(path).

But I hope I can add some option to indicate next() to make a replace jump.

Thank you.

2.x feature request

Most helpful comment

This is exactly the same problem I'm having. I'm glad this issue is here because I was hunting around for an option to pass to next() since the option's fields (such as query) are not documented (path is the only one documented).

And yes, $router.go(-1) needs to be called twice (or back button pressed twice) after a redirect. Replace seems to be necessary in this case.

All 7 comments

Hmm.. could be useful. Maybe a second parameter for next? next(path, useReplace)
/ping @posva @LinusBorg

@hiyuki Why do you need a replace rather than a push? Can you tell us a bit about your use case, please?

I use it as a conditional redirect and doesn't allow user to go back

I use this in beforeEach. When I click the back button at the first time, it won't do anything. I need to click twice. I had to replace next with router.replace after #795 fixed.

This is exactly the same problem I'm having. I'm glad this issue is here because I was hunting around for an option to pass to next() since the option's fields (such as query) are not documented (path is the only one documented).

And yes, $router.go(-1) needs to be called twice (or back button pressed twice) after a redirect. Replace seems to be necessary in this case.

@fnlctrl Aborting the navigation doesn't remove it from history?

No.. there's no browser API to remove anything from history. Therefore,
every navigation is made directly, and aborting a transition will make
vue-router replace the current history with the previous one.

On Sat, Nov 26, 2016 at 11:14 PM Eduardo San Martin Morote <
[email protected]> wrote:

@fnlctrl https://github.com/fnlctrl Aborting the navigation doesn't
remove it from history?

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/vuejs/vue-router/issues/897#issuecomment-263068483,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFTLl3QQzMcfnohUL2xs3BNTEW6AgylKks5rCEzmgaJpZM4KvlvM
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yyx990803 picture yyx990803  Â·  3Comments

posva picture posva  Â·  3Comments

gil0mendes picture gil0mendes  Â·  3Comments

achen224 picture achen224  Â·  3Comments

mitar picture mitar  Â·  3Comments