Home  >  Q&A  >  body text

Adding URL queries to paths in Vue.js router: a step-by-step guide

This is how to use routing in the template Component.vue:

<router-link :to="{ name: 'club' }">
  <lazy-image
    src="club.jpg"
    class="club_class"
    alt="Club alt"
  />
</router-link>

This is how it is defined in router.js:

const routes = [
    {
        path: '/s/site',
        name: 'club',
        component: () => import('./_pages/Club'),
    },
];
export default routes;

I need to add a static parameter to the link like this:

'?foo=bar'

I tried hardcoding it in Component.vue with no success. Should I define it as param in router.js or somewhere else?

P粉076987386P粉076987386258 days ago371

reply all(1)I'll reply

  • P粉232409069

    P粉2324090692024-02-04 00:30:17

    Use this code:

    go

    reply
    0
  • Cancelreply