mireiabm
mireiabm

Reputation: 11

How to give access to a route in Vue.js only througth router link

I have the route /myPath in my Vue.js application. I want it to be accesible only througth a router-link. Else, if an user tries to access directly he will be redirected to "not found" page.

Is this possible with Vue.js router features/functionalities?

Upvotes: 0

Views: 42

Answers (1)

srdecny
srdecny

Reputation: 603

You can check the route user is trying to navigate from using Navigation Guards. Something like this, for example:

router.beforeEach((to, from, next) => {
    if (from === "route_with_the_router_link") {
        next()
    } else {
        next(false)
    }
})

Upvotes: 1

Related Questions