0

I want to use the URL params and Queries into the vue router defining file in order to set the title name dynamically.

I tried to use the $route.params.paramName format:

const routes = [
 {
    path: '/rooms/:room/:id?',
    name: `${$route.params.room}`,
    component: RoomsView,
    meta:{
      title: `${$route.params.room} ${$route.params.id} - WebsiteName`
    }
  }
]

Do you know how can I access these values?

1 Answer 1

1

I think it's best to let the component itself render the logic with something like

computed: {
 title() {
  const { name, id } = this.$route.params; 
  return `${name} ${id} - WebsiteName`;
 }
}

I think the docs would give you some useful insight as well

Sign up to request clarification or add additional context in comments.

4 Comments

I tried this and it didn't change the metadata title field (the title shown on the browser's tab)...
Can you post a little sandbox so I can reproduce your issue?
@sifislaz there is no way to set Title of the browser's tab through vue-router. Meta tags aren't for browsers, it's for navigation guards. You can change it through document object. Something like this: document.title = "New title".
Apparently you can access the parameters from the navigation guard and build there the reactive title of your document. Thanks a lot for your help.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.