How to add optional parameters with Vue Router?

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.