[Vuejs]-How i can get router params in apollo ? [VUE3]

0๐Ÿ‘

โœ…

If your routes looked like this

const routes = [{ path: '/user/:id', component: User }]

then to get that id param on your component you just do as below

const User = {
   // make sure to add a prop named exactly like the route param
   props: ['id'],
  template: '<div>User {{ $route.params.id }}</div>'
}

and this works on your template as well

<template>
   <div>User {{ $route.params.id }}</div>
</template>

But as for your case, it seems like you want to use it on your setup() function.
The way you access it is as below

import { useRoute } from 'vue-router';

export default {
 setup(){
  const route = useRoute();
  //console.log(route.params.parameterName)
}
}

Leave a comment