1

I defined a dynamic parameter in my router. This parameter receives certain parameter values ​​even if it is dynamic.

example:

{
  path: '/:type',
  component: List,
}

There are 2 or 3 parameters that the router can take. for example, the parameters it can take are 'actual' and 'archive'

I want to redirect to 404 when the user types a parameter other than '://localhost:8080/actual' or '://localhost:8080/archive'. I can do this in the .vue file, but I want to make adjustments in the router file.

1 Answer 1

2

You can set up a Per-Route Guard on the route configuration itself

{
  path: '/:type',
  component: List,
  beforeEnter: (to, from, next) => {
    //check the params
    if(to.params.type === 'actual' ||to.params.type === 'archive'){
      next();
    }else{
      next('/404');//error route
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.