我在我的应用程序中遵循这个官方示例,它显示了如何<router-outlet>
在 {N} 中实现 a。我的应用程序的唯一区别是我想在模式页面中使用它。但它不是<router-outlet>
模态中的元素,而是将内容加载为新页面。
模态组件
...
@Component({
selector: "modal",
template: `
<StackLayout>
<StackLayout>
<Button text="First" [nsRouterLink]="['/first']"></Button>
<Button text="Second" [nsRouterLink]="['/second']"></Button>
</StackLayout>
<router-outlet></router-outlet>
</StackLayout>
`
})
export class ModalComponent {
constructor(private page:Page, public params:ModalDialogParams) {
// ..
}
}
app.routing.ts
...
export const routes:Routes = [
{ path: "", redirectTo: "home", pathMatch: "full" },
{ path: "home", component: HomeComponent },
{ path: "modal", component: ModalComponent },
{ path: "first", component: FirstComponent },
{ path: "second", component: SecondComponent }
];
export const dynamicComponents = [
ModalComponent,
FirstComponent,
SecondComponent
];
...
app.module.ts
...
@NgModule({
imports: [
NativeScriptModule,
NativeScriptFormsModule,
NativeScriptHttpModule,
NativeScriptRouterModule,
NativeScriptRouterModule.forRoot(routes)
],
declarations: [
AppComponent,
HomeComponent,
...dynamicComponents
],
entryComponents: [
...dynamicComponents
],
bootstrap: [AppComponent]
})
export class AppModule {}
知道为什么/first
并/second
导航到新页面而不是将其加载到模式的路由器出口中吗?
更新:
这似乎是一个错误。请看下面我的回答。