I have this route path
/custom/:length(\\d+-letter-)?words
It matches below routes as expected ✅
/custom/3-letter-words
/custom/words
However, this.$route.params.length returns 3-letter-.
My expectation is that this.$route.params.length will return 3 as a result and the route path I entered will match both routes above.
In this case, how should I change the route path above? If you think that it won't work by changing the route path, do you have any other suggestions?
You could try
which would output the correct value for length, but this would also match
/custom/-letter-words.Unfortunately you can't use
:length(?:(\\d+)-letter-)?with vue-router, it doesn't parse it correctly.Another option would be to use props in function mode: