0

I saw a line of code in a project that I just started working on. So, I am kind of new to Vue.js. The code is as below:

 routes: [{
    path: '/coursePage/:contentId/:title?',
    name: 'coursePage',
    component: coursePage,
    meta: {requireAuth: false}
  },

The route param - contentId works fine but I can't figure out the purpose of ? in param - title? Can anyone help me understand this? Thanks.

1

1 Answer 1

3

The last ? means this parameter is optional.

The vue-router will not complain if you do not pass this parameter while building the dynamic route.

You can do

this.$router.push({
    name: coursePage,
    params: { contentId: 1 }
})

or

this.$router.push({
    name: coursePage,
    params: { contentId: 1, title: 2 }
})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.