如何在Angular 2-6中正确使用路线?

时间:2019-07-19 11:33:12

标签: angular angular6 angular2-routing

请停止在我的帖子中使用MINUSES,我真的不明白为什么会出现错误并且无法打开页面。如果您能说我写的东西-错误,请发表评论。

如何使用路线? 我有一个模块(应用程序模块),我想为我的应用程序使用2个不同或更多的模板,我也曾在Google中搜索并找到了解决方案,但这是行不通的,我也不知道为什么

我的结构: app.module <-app.routing-

但是,如果我添加任何模块或路由到另一个组件,我只是出错,我的测试代码在 App.routing

V1::所有页面都应按管理模板查看吗?

const routes: Routes = [
  {
    path: "",
    redirectTo: "dashboard",
    pathMatch: "full"
  },
  {
    path: "",
    component: AdminLayoutComponent,
    children: [
      {
        path: "",
        loadChildren:
          "./layouts/admin-layout/admin-layout.module#AdminLayoutModule"
      },
      {
        path: "test",
        component: TestPageComponent
      }
    ]
  }
];

@NgModule({
  imports: [
    CommonModule,
    BrowserModule,
    RouterModule.forRoot(routes, {
       useHash: false
    })
  ],
  exports: [
  ],
})
export class AppRoutingModule { }

如果我尝试打开页面-测试-我收到错误消息:

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'split' of undefined
TypeError: Cannot read property 'split' of undefined
    at Ot (router.js.pre-build-optimizer.js:530)
    at Ue (router.js.pre-build-optimizer.js:2717)
    at t.matchSegmentAgainstRoute (router.js.pre-build-optimizer.js:2564)
    at t.expandSegmentAgainstRoute (router.js.pre-build-optimizer.js:2515)
    at e.project (router.js.pre-build-optimizer.js:2488)
    at e._next (map.js.pre-build-optimizer.js:35)
    at e.next (Subscriber.js.pre-build-optimizer.js:53)
    at t._subscribe (subscribeToArray.js.pre-build-optimizer.js:5)
    at t._trySubscribe (Observable.js.pre-build-optimizer.js:43)
    at t.subscribe (Observable.js.pre-build-optimizer.js:29)
    at D (zone.js.pre-build-optimizer.js:852)
    at D (zone.js.pre-build-optimizer.js:809)
    at zone.js.pre-build-optimizer.js:913
    at t.invokeTask (zone.js.pre-build-optimizer.js:423)
    at Object.onInvokeTask (core.js.pre-build-optimizer.js:24328)
    at t.invokeTask (zone.js.pre-build-optimizer.js:422)
    at e.runTask (zone.js.pre-build-optimizer.js:195)
    at g (zone.js.pre-build-optimizer.js:601)

V2 :是否应该单独测试页面视图模板?

const routes: Routes = [
  {
    path: "",
    redirectTo: "dashboard",
    pathMatch: "full"
  },
  {
    path: "",
    component: AdminLayoutComponent,
    children: [
      {
        path: "",
        loadChildren:
          "./layouts/admin-layout/admin-layout.module#AdminLayoutModule"
      }
    ]
  },
  {
    path: "test",
    loadChildren: "./test/test.module#TestModule"
  }
];

该代码也不起作用。

我不知道自己做了什么,但是很早就起作用了,这可能是什么问题?

0 个答案:

没有答案