Question

Consider (excerpt from the AngularDart tutorial):

router.root
  ..addRoute(
      name: 'add',
      path: '/add',
      enter: view('view/addRecipe.html'))

How is a URL matched with such a path? Is there an implicit wildcard suffix like /add/* or maybe /add*? If so, how can I make /add match exactly /add to avoid conflicts with, say, /address?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top