Categories
Vue Answers

How to add optional parameters with Vue Router?

Spread the love

Sometimes, we want to add optional parameters with Vue Router.

In this article, we’ll look at how to add optional parameters with Vue Router.

How to add optional parameters with Vue Router?

To add optional parameters with Vue Router, we can append a ? after the route parameter placeholder.

For instance, we write

const routes = [
  {
    path: "/offers/:member?",
    //...
  },
];

//...

to make the member URL parameter optional.

Conclusion

To add optional parameters with Vue Router, we can append a ? after the route parameter placeholder.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *