Angular Dart: matching rules for route path - implicit suffix wildcard?
Correct, UrlTemplate
does a naive prefix match, so /add
will match /address
.
If you are worried about conflicts between two routes where path of one happens to be a prefix of another, then the correct approach is to put the most specific path first. For example:
router.root ..addRoute( name: 'address', path: '/address', enter: view('view/address.html')) ..addRoute( name: 'add', path: '/add', enter: view('view/addRecipe.html'))
Router matches routes in the order they are specified, so it will pick the first that matches. This way /address
will always match address
route and /add
will always match add
route.
If you are worried about unintended matches of /addFoo
to /add
, at the moment I'm afraid there's no easy way to ensure that. If you feel strongly about it please file a feature request against the route_hierarchical package.
If you check out the source code (client.dart in route_hierarchial package, which in turn is used by AngularDart) you will notice that path is used as a key into a map. This means that if your path is set to /add
it will not match /address
.