Reputation: 3264
I'm working with the official vue-router of vue.js.
I'm currently trying to get a route to match using dynamic route matching. Since vue-router uses path-to-regexp under the hood, one can use regex in a route path as described here. You can find an example of the vue-router using this feature here.
This is my route:
{
path: '/a/:id/(r/:generic1/)?s/:name/a'
}
Here some examples that DO work:
'/a/1234/s/Foo/a' // => {0: undefined, id: "1234", name: "Foo"}
'/a/23456/s/Bar/a' // => {0: undefined, id: "23456", name: "Bar"}
Here some examples that DO NOT work, but SHOULD:
'/a/1234/r/Bar/s/Foo/a' // => {id: "1234", generic1: "Bar", name: "Foo"}
'/a/23456/r/Baz/s/Goo/a' // => {id: "1234", generic1: "Baz", name: "Goo"}
.. what am I doing wrong here? One of the examples states the following:
make part of the path optional by wrapping with parens and add "?" [sic]
I think these paths should match the given route.
Upvotes: 1
Views: 3340
Reputation: 1091
According to this comment, you can't put params inside the regexp area.
I think you can do something like this /a/:id/r?/:generic1?/s/:name/a
this should match all of your examples and also preserves the generic1 param.
I verified this solution with the Express Route Tester.
Upvotes: 1