本文介绍了Angular 路由器“**"通配符作为子路由的包罗万象?使用最新的 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 可以是任何东西.

      anything and otherthing can literally be anything.

      我希望的路由配置可以工作,但最终接管了定义的路由,其中​​ https://domain.com/profile 会触发 catchall ('**'),这似乎很奇怪,因为在我的理解中,catchall 应该只触发或捕获未在其上方定义的路由:

      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",
      

      等等...

      这篇关于Angular 路由器“**"通配符作为子路由的包罗万象?使用最新的 2.4.0 和路由器 3.4.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 00:40