角路由器"**"通配符可以与子路由一起使用吗?使用最新的2.4.0和路由器3.4.1 [英] Angular router '**' wildcard as a catch-all with child routes? Using latest 2.4.0 and Router 3.4.1

查看:54
本文介绍了角路由器"**"通配符可以与子路由一起使用吗?使用最新的2.4.0和路由器3.4.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试数十种配置,以使其正常运行,但无法弄清楚.

I've been experimenting with dozens of configurations trying to get this to work but cannot figure this out.

给出如下网址:

  • https://domain.com 仪表板
  • https://domain.com/profile 个人资料
  • https://domain.com/anything ...全部带孩子.
    • https://domain.com Dashboard
    • https://domain.com/profile Profile
    • https://domain.com/anything ...catch all with children.
      • https://domain.com/anything/edit

      anythingotherthing可以是任何东西.

      我希望可以进行路由配置,但是最终会接管定义的路由,其中​​ https://domain.com/profile 会触发通用指令('**'),这似乎很奇怪,因为据我了解,通用指令应仅触发或捕获在其上方未定义的路线:

      A route configuration I hoped would work but ends up taking over the defined routes where https://domain.com/profile would trigger the catchall ('**'), which seems very odd since to my understanding, the catchall should only fire or catch routes that are not defined above it:

      app.module的位置:

      export const routes = [
        {
          path: '',
          loadChildren: 'app/dashboard/dashboard.module'
        },
        {
          path: 'profile',
          loadChildren: 'app/profile/profile.module'
        },
        {
          path: '**',
          loadChildren: 'app/anything/anything.module'
        }
      ];
      
      @NgModule({
        imports: [
          BrowserModule,
          RouterModule.forRoot(routes)
        ],
        declarations: [AppComponent]
        bootstrap: [AppComponent]
      })
      export class AppModule {}
      

      anything.module的位置:

      const routes = [
        {
          path: ':id',  // hoping to pick up the wildcard as param this way
          component: AnyComponent,
          children: [
            {
              path: 'edit',
              component: EditComponent
            }
          ]
        }
      ];
      
      @NgModule({
        imports: [
          CommonModule,
          RouterModule.forChild(routes)
        ],
        declarations: [
          AnyComponent,
          EditComponent
        ]
      })
      export default class AnythingModule {}
      

      是否有必要使上述用例与Angular Router 3.4.1一起使用?

      Is there anyway to make the above use case work with the Angular Router 3.4.1?

      推荐答案

      这是一年前提出的.但是我使用的是Angular 5.1.2,发现自己遇到了同样的问题

      This was asked a year ago. However I was using Angular 5.1.2 and found myself with the same problem

      这是路由器的一个错误,已在问题# 18139 中解决了到我的package.json上的5.2.1进行修复

      This was a bug with the router solved on issue #18139, I updated to 5.2.1 on my package.json to get the fix

      "@angular/core": "^5.2.1",
      "@angular/forms": "^5.2.1",
      "@angular/http": "^5.2.1",
      

      等...

      这篇关于角路由器"**"通配符可以与子路由一起使用吗?使用最新的2.4.0和路由器3.4.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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