Router parameter naming style conversion #468
Replies: 8 comments 1 reply
-
You can indeed automatically convert them by using the extendRoute(route) {
// transform kebab-case to camelCase
route.params.forEach((param, i) => {
const newParam = param.paramName.replace(/-([a-z])/g, (g) =>
g[1].toUpperCase()
)
route.path = route.path.replace(`:${param.paramName}`, `:${newParam}`)
param.paramName = newParam
})
} But also, the generated TS should be correct, so it should be |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer. Will this become a built-in feature? |
Beta Was this translation helpful? Give feedback.
-
Right now I don’t think it needs a dedicated option |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I updated the function, it does require you to change the path too. |
Beta Was this translation helpful? Give feedback.
-
Not work, but got warning: |
Beta Was this translation helpful? Give feedback.
-
That's #341, so you will need a bit more code to handle it right now |
Beta Was this translation helpful? Give feedback.
-
I'm still not convinced at all for the need of an option to handle this. Naming the files so they match vue router params seems like a good practice |
Beta Was this translation helpful? Give feedback.
-
Currently, if I have
pages/user/[u-id]/group/[g-id].vue
, it will generate params like:And
u-id
andg-id
are not valid JavaScript attribute names.Is it possible to add some kind of automatic conversion? It should also be configurable to convert to multiple naming styles, like camelCase, underscores or raw style.
Beta Was this translation helpful? Give feedback.
All reactions