Angular Dart:路由路径的匹配规则

编程入门 行业动态 更新时间:2024-10-27 06:29:07
本文介绍了Angular Dart:路由路径的匹配规则 - 隐式后缀通配符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-22 12:04:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023501.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   路径   规则   Angular   Dart

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!