关于带有离子4

时间:2018-12-06 12:16:53

标签: angular ionic-framework

我对应该如何工作感到有些困惑。我正在尝试使用具有多个出口的不同教程,但是大多数情况下结果是:

  

错误错误:未捕获(承诺):错误:无法匹配任何路由。   网址段:'apath'

我有很多问题:

1) forChild声明的行为方式,特别是在使用不同路径声明同一组件时尤其如此? ->例如,每次使用CLI生成新页面时,都会创建一个新的page.module.ts,并且还会以LzyLoaded方式使用新组件的路由更新app.routing.module.ts。 但是在新模块中,还有一条类似这样的路由:

const routes: Routes = [
  {
    path: '',
    component: SortPopoverPage
  }
];

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    RouterModule.forChild(routes)
  ],
  declarations: [SortPopoverPage]
})
export class SortPopoverPageModule {}

据我所知,此路由将与在inapp.routing.module中声明的其他路由连接起来,由于空路径已被重定向到home,因此将永远无法到达。 为什么CLI会创建此路由?

2)辅助路线的语法:我在官方指南https://angular.io/guide/router中看到了类似 / path(outlet:path)的语法,但在其他指南中也看到了教程 / path /(出口:路径) https://www.joshmorony.com/creating-a-tabs-layout-with-angular-routing-and-ionic-4/

哪个是好人?

3)当您必须在URL中指定目的地时,为什么还要在路由声明中记下目的地出口?如果您尝试在其他插座中加载用其他插座声明的路径,会发生什么情况?

{
    path: 'filter',
    outlet: 'popover',
    component: FilterPopoverPage
  }

 <ion-item href="/home(popover:test/filter)">test</ion-item>

4)更具体地说:单击链接时,我试图在专用插座中加载组件:

home.html:

<ion-content>
...
<ion-item href="/home(popover:filter)">test</ion-item>
...
<ion-router-outlet name="popover"></ion-router-outlet>
</ion-content>

app.routing.module:

const routes: Routes = [
  {path: 'home', component: HomePage},
  {path: 'filter', outlet: 'popover', component: FilterPopoverPage},
  {path: '', redirectTo: 'home', pathMatch: 'full'},
];

当我按一下测试按钮时,什么也没发生,我认为页面已重新加载,但控制台中没有错误。 如果我使用路径/ home /(popover:filter),则会收到错误消息:

  

错误错误:未捕获(承诺):错误:无法匹配任何路由。   网址段:“家”

明确定义了“家庭”路径后,对吗?

感谢您的帮助。

0 个答案:

没有答案