vuejs / vue-router

🚦 The official router for Vue 2
http://v3.router.vuejs.org/
MIT License
18.99k stars 5.06k forks source link

Improved error messages on bad file names #3836

Closed rcrane closed 1 year ago

rcrane commented 1 year ago

What problem does this feature solve?

Using Vue-Press to convert markdown into websites, I ran into the issue that in certain conditions a ":" in the file name is interpreted by vue-router.

"2023-03-28T11:56:34+02:00.md" fails the compilation while "2023-03-28T11:5634+02:00.md" works.

This is the error message thrown:

Error: ERR (1)/"34": A repeatable param (34) must be alone in its segment. eg: '/:ids+.
    at crash (file:///build/node_modules/vue-router/dist/vue-router.mjs:1092:15)
    at consumeBuffer (file:///build/node_modules/vue-router/dist/vue-router.mjs:1126:17)
    at tokenizePath (file:///build/node_modules/vue-router/dist/vue-router.mjs:1178:21)
    at createRouteRecordMatcher (file:///build/node_modules/vue-router/dist/vue-router.mjs:1225:35)
    at addRoute (file:///build/node_modules/vue-router/dist/vue-router.mjs:1318:23)
    at file:///build/node_modules/vue-router/dist/vue-router.mjs:1486:29
    at Array.forEach (<anonymous>)
    at createRouterMatcher (file:///build/node_modules/vue-router/dist/vue-router.mjs:1486:12)
    at createRouter (file:///build/node_modules/vue-router/dist/vue-router.mjs:2942:21)
    at createVueRouter (file:///build/docs/.vuepress/.temp/.server/app.00b70600.mjs:3677:18)

This is understandable, once you know what's happening.

My feature request is to add a more easy-to-understand message to the above error.

Could "Filename to route conversion error." be added to the error message in e.g. vue-router.mjs:1092:15 ? It would help a lot to easily spot the issue by those not fully awary of how vue-route interpretes file names. With regard to end user experience, this easier error message allows one to faster see what the real issue is.

For reference, this is the request in vuepress, before finding out that vue-router is the better place: https://github.com/vuepress/vuepress-next/issues/1293

What does the proposed API look like?

Add "Filename to route conversion error." to vue-router.mjs:1178:21 or vue-router.mjs:1092:15.

posva commented 1 year ago

The : has a special meaning in vue router (parameters) so you need to escape it but this can only be changed in your filenames or in vuepress.

rcrane commented 1 year ago

Thanks for the feedback. The request was more about improving the error message to guide users a bit better.