AngularDart:路由名称的层次结构的命名空间? [英] AngularDart: Namespace of route names hierarchical too?

查看:189
本文介绍了AngularDart:路由名称的层次结构的命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下级别路线的初始化(摘自 AngularDart教程) :

Consider the following initialization of hierarchical routes (excerpt from the AngularDart tutorial):

router.root
  ..addRoute(
      name: 'add',
      path: '/add',
      enter: view('view/addRecipe.html'))
  ..addRoute(
      name: 'recipe',
      path: '/recipe/:recipeId',
      mount: (Route route) => route
          ..addRoute(
              name: 'view',
              path: '/view',
              enter: view('view/viewRecipe.html'))
          ..addRoute(
              name: 'edit',
              path: '/edit',
              enter: view('view/editRecipe.html'))
          ..addRoute(
              name: 'view_default',
              defaultRoute: true,
              enter: (_) =>
                  router.go('view', {'recipeId': ':recipeId'},
                      startingFrom: route, replace:true)));

虽然我明白一个子路径的路径将是唯一的(从祖先的路径构造)

While I understand that a subroute's path will be unique (being constructed from the paths of its ancestors), is the route name namespace hierarchical too or must the names be unique?

推荐答案

要求路由名称对于所有直接路由都是唯一的

It's required that the route names are unique for all direct children of a given parent.

确定:

foo
   bar
   baz
qux
  foo
     bar
     baz

不OK:

foo
   bar
   bar

一般来说,为了更好的可读性,建议使用唯一的路由名称,尽管这不是必需的。

In general it's recommended to have unique route names throughout, for better readability, although it's not a requirement.

引用路由时,必须从根路径指定路由的完整路径 foo.bar.baz ,或提供相对路径route anchor router.go('foo',parameters:{},startingFrom:bar)

When referencing a route, one must specify the full path of the route foo.bar.baz from the root, or provide a relative route anchor router.go('foo', parameters: {}, startingFrom: bar)

非唯一的路由名可能导致问题是与查询参数,因为查询参数以路由名称(而不是完整路径)为前缀,并且可能导致具有相同名称的路由之间的值泄漏( / foo ?foo.param1 = value )。也就是说,查询参数支持是一个正在进行的工作,所以事情可能会改变。

One place where non-unique route names can cause issues is with query parameters, as query parameters are prefixed with the route name (not the full path), and can cause leaking of values between routes with the same name (/foo?foo.param1=value). That said, query parameter support is a work-in-progress, so things might change.

这篇关于AngularDart:路由名称的层次结构的命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆