Prefix param typing #311
-
I'm extending my routes by adding import { createRouter, createWebHistory } from "vue-router/auto"
import type { RouteRecordRaw } from "vue-router/auto"
function prefixPathDeep(routes: RouteRecordRaw[], prefix: string): RouteRecordRaw[] {
return routes.map((route) => {
if (route.path && !route.children) {
route.path = route.path.startsWith(prefix) ? route.path : prefix + "/" + route.path
}
if (route.children) {
route.children = prefixPathDeep(route.children, prefix)
}
return route
})
}
export const router = createRouter({
history: createWebHistory(import.meta.env.VITE_BASE_URL),
extendRoutes(routes) {
return prefixPathDeep(routes, "/:lang")
},
}) How to allow the router to infer that parameter, for example I've : router.push({
name: 'Products',
params: { lang: locale },
}) I got the error
|
Beta Was this translation helpful? Give feedback.
Answered by
posva
Feb 13, 2024
Replies: 1 comment 5 replies
-
VueRouter({
routesFolder: [
// can add multiple routes folders
{
src: 'src/pages',
// can even add params
// path: '[lang]/',
},
]
}) |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
posva
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
extendRoutes
is runtime only. In your case you can add that prefix to all routes in the config withroutesFolder
: