Today I’m facing a problem and I could use some advice.
I have a route page structure like {url}/:id. My objective is to prevent users from navigating to the previous and next pages within the same route, for example, from {url}/1 to {url}/2. I am making API calls to change the data on the page, and the URL does change accordingly.
However, I want users to be able to navigate to the page before or after the {url}/:id, but not within the {url}/:id itself.
Is there any solution or advice you can provide? I have heard that navigation guards might be helpful, but I find them difficult to understand initially.
Thank you in advance for your assistance!
Sorry for bad explanation, I need the browser remember the prev page or next page is another, like {url}/lists or {url}/news, but does not remember the same route page, so it won’t go to the same route page after clicking the button on the browser…
2
Answers
I found that this.$router.replace({ path: '/your-route' }); instead of router.push solved my problem.
Here’s a high-level example using Vue Router: