问题描述
限时送ChatGPT账号..考虑(摘自 AngularDart 教程):
router.root
..addRoute(
name: 'add',
path: '/add',
enter: view('view/addRecipe.html'))
URL如何匹配到这样的路径?是否有像 /add/*
或 /add*
这样的隐式通配符后缀?如果是这样,我怎样才能使 /add
完全匹配 /add
以避免与 /address
发生冲突?
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
?
推荐答案
正确,UrlTemplate
做了一个简单的前缀匹配,所以 /add
将匹配 /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 按照指定的顺序匹配路由,所以它会选择第一个匹配的.这样 /address
将始终匹配 address
路由,/add
将始终匹配 add
路由.
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.
如果您担心 /addFoo
与 /add
的意外匹配,目前恐怕没有简单的方法可以确保这一点.如果您对此有强烈的看法,请针对 route_hierarchical 包提交功能请求.
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.
这篇关于Angular Dart:路由路径的匹配规则 - 隐式后缀通配符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论