Question3r
Question3r

Reputation: 3802

reset route instead of adding a new route to the current one

I want to create a router navigation and prevent 404 errors. When manipulating a valid URL to an invalid one the next router link won't work anymore. I created a working example

https://codesandbox.io/s/8l60y06pmj

To see the problem do the following steps:

Now you should have the following URL

https://8l60y06pmj.codesandbox.io/#/pageTwo/pageThree

but the correct URL should be

https://8l60y06pmj.codesandbox.io/#/pageThree

You can reset this behaviour by clicking on the link navigating to the home view.

How can I fix this?

Upvotes: 0

Views: 254

Answers (1)

Matt Jenkins
Matt Jenkins

Reputation: 191

Inside of NavbarComponent.vue, you need to add a / to both of the page links; it should look something like this after the changes.

<router-link to="/pageTwo">Page Two</router-link> | 
<router-link to="/pageThree">Page Three</router-link>

Without that slash, you aren't actually telling Vue Router to send the user to a new page.

Here's a working version of your CodeSandbox.

Upvotes: 1

Related Questions