本文介绍了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

不好:

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,或提供相对路由锚router.go('foo',参数:{},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:路由名称的命名空间也是分层的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 21:29