Reputation: 183
I have a path-string like "/foo/123/bar/456"
, which is not the current path.
The Vue Router path is set to match /foo/:fooid/bar/:barid
Is there a way to use Vue Router to retrieve the params from the string?
Expected:
let params = this.$router.someFunction("/foo/123/bar/456")
// params = {fooid: 123, barid: 456}
Upvotes: 1
Views: 851
Reputation: 4464
What you are looking for is this.$router.resolve("/foo/123/bar/456")
Note, that it will only match route if there is one corresponding in your routes. The method will give you the Object with "params" property.
const matchedRoute = this.$router.resolve("/foo/123/bar/456")
// what you are looking for is under
// matchedRoute.params = {fooid: 123, barid: 456}
Upvotes: 1