Angular 路由器 '**' 通配符作为子路由的包罗万象?使用最新的 2.4.0 和路由器 3.4.1

标签 angular angular2-routing

我一直在试验数十种配置,试图让它发挥作用,但无法解决这个问题。

给定的url如下:

anythingotherthing 可以是任何东西。

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

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 一起工作?

最佳答案

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

这是在问题 # 18139 上解决的路由器错误,我在我的 package.json 上更新到 5.2.1 以获得修复

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

等...

关于Angular 路由器 '**' 通配符作为子路由的包罗万象?使用最新的 2.4.0 和路由器 3.4.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40276372/

相关文章:

javascript - Angular 4 : Redirecting user to last visited page in previous session on login

angular - 找不到要加载的主 socket 'LocalizationListComponent'

angular - 不支持调用 Angular2SocialLoginModule 函数调用

javascript - 如何在没有重定向的情况下使用空的 href 属性?

unit-testing - 第 3 方库测试 angular 2 webpack

angular - 从组件手动将服务注入(inject)到指令中

Angular Material DatePicker : Date becomes one day before selected date

javascript - 如何在 Angular 2 JS 中使用管道?

javascript - 单元测试时,无法在 Angular RC 5 中解析路由器 : (?、?、?、?、?、?、?) 的所有参数

angular - 如何在 Angular/Jasmine 中测试 Filereader.onload 回调函数?