角度Dart:路由路径的匹配规则 - 隐式后缀通配符? [英] Angular Dart: matching rules for route path - implicit suffix wildcard?
问题描述
考虑(摘自 AngularDart教程):
router.root
..addRoute(
name:'add',
path:'/ add',
enter:view('view / addRecipe.html'))
$ b b
如何将网址与此类路径进行匹配?是否有隐式通配符后缀,例如 / add / *
或可能 / add *
?如果是这样,我如何使 / add
完全匹配 / add
,以避免与 / address
?
正确, UrlTemplate
做一个简单的前缀匹配, code> / add 将匹配 / address
。
担心两条路径之间的冲突,其中一条路径恰好是另一条路径的前缀,则正确的方法是将最具体的路径放在第一条。例如:
router.root
..addRoute(
name :'address',
path:'/ address',
enter:view('view / address.html'))
..addRoute(
name:'add' ,
path:'/ add',
enter:view('view / addRecipe.html'))
路由器按照它们指定的顺序匹配路由,所以它将选择匹配的第一个。这种方式 / address
将始终匹配地址
路由和 / add
如果您担心 / < addFoo
到 / add
,现在恐怕没有简单的方法来确保。如果您对此感到非常满意,请针对route_hierarchical程序包提交功能请求。 / p>
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
?
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.
这篇关于角度Dart:路由路径的匹配规则 - 隐式后缀通配符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!