dart - Angular Dart中的分层路径参数

标签 dart angular-dart

我有一个简单的测试设置:一个带有参数A的路由parA和一个带有参数B的子路由parB

    'A' : ngRoute 
    (
        path : '/A/:parA',
        enter: (RouteEnterEvent e)
        {
            print ('ENTERED A');
            e.parameters.keys.forEach(print);
        },
        mount: 
        {
            'B' : ngRoute
            (
                path: '/B/:parB',
                enter: (RouteEnterEvent e)
                {
                    print ('ENTERED B');
                    e.parameters.keys.forEach(print);
                }
            )
        }
    )

当我去/#/A/1234/B/5678时,我期望得到
Entered B 
parA
parB

相反,我得到了
Entered A
parA
Entered B
parB

这意味着在B中创建的组件的构造函数具有RouteProvider的组件无法访问参数parA

最佳答案

似乎与此问题有关https://github.com/angular/route.dart/issues/85
也许那里列出的解决方法也适用于您。

从问题复制:

As a current workaround I have a helper method that goes through all parent routes and adds them to the RouteEvent.



/// Adds the parameters of all parent routes to [e].
RouteEvent _addParentParams(RouteEvent e) {

  // Function to recursively get the parents.
  Function recursiveAddParentParams;
  recursiveAddParentParams = (Route route) {
    // Set the parent parameters to the event.
    e.parameters.addAll(route.parameters);

    if (route.parent != null) {
      recursiveAddParentParams(route.parent);
    }
  };

  recursiveAddParentParams(e.route.parent);

  return e;
}

关于dart - Angular Dart中的分层路径参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27910961/

相关文章:

regex - 检查字符串是否有效,位智实时 map 链接

angular - 强制 Angular 不对某些 @Input 进行更改检测

dart - map : const {'foo' :'&foo' } in AngularDart?的注解等价物是什么

dart - 使用带 Dartium 的 `pub serve` 时如何查看 HTML 模板和 CSS 错误?

dart - 使用AngularDart组件在列表中打开展开的项目

android - 断言宽度 > 0.0' : is not true when placing single Image in Container in FittedBox 失败

dart - 使用组件 onAttach 的 ShadowRoot

sqlite - 被解雇的 Dismissible 小部件仍然是 flutter 树的一部分

flutter - 如何在Flutter应用中应用调色板编号?

dart - Angular-dart 组件并不总是显示在网络应用程序中