1
votes

With the router-link tag with vue-router, "Setting replace prop will call router.replace() instead of router.push() when clicked, so the navigation will not leave a history record", according to the docs. But this doesn't seem to be happening for me, so I think I must be misunderstanding something. I have a navigation menu in my SPA and the router-link in each menu item has a replace prop. Yet when I click on each menu item in turn, it clearly does add to the history, in that the back button takes me back to the previous item, and I can actually see in the Firefox history the list of URLs being added to. What am I doing wrong?

1
a demonstration of that behaviour, at least the HTMLtemplate, would be helpful in helping you. - Linus Borg
Well, an example of one of the router-links is this: <router-link :to="{ name: 'edit-sale', params: { action: 'add' }}" replace>New Sale</router-link>. That uses this route: {name: 'edit-sale', path: '/sale/:action(add|modify)/:id?', component: SaleManager}. HOWEVER...I find now that the back button is behaving as expected, so maybe I had just run into some cacheing issue? - John Moore
Spoke too soon! With Chrome, I can keep clicking the back button and move through my navigation history - '/product/list', '/sale/add', whatever, even though all these links have been given the 'replace' prop. I don't think it's a bug, more a misunderstanding on my part. - John Moore

1 Answers

5
votes

use <router-link :to='{path:'/test'}' replace> Go <router-link> in component "history",after clicking "Go", the url is "..../test",the "history" component's url is still in url's history list. but if you click back button of browser, '.../history' is disappeared .[Vue.2]