我的routing.ts代码有问题。因此,我尝试了以下代码:
const routes: Routes = [
{
path: 'home', component: HomeComponent, canActivate: [AuthGuard], children: [
{ path: 'fp', component: FirstPageComponent },
{ path: 'events', component: EventsComponent },
{ path: 'package', component: PackageComponent },
{ path: 'package/:id', component: PackageGetByIdComponent },
{ path: 'settings', component: SettingsComponent },
{ path: 'profile', component: ProfileComponent }
]
},
{ path: 'login', component: LoginFirstComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'usersforgetpassword', component: ResetPassComponent },
{ path: '**', redirectTo: 'home', pathMatch: 'full'},
];
@NgModule({
imports: [NativeScriptRouterModule.forRoot(routes)],
exports: [NativeScriptRouterModule]
})
export class AppRoutingModule { }
我要在FirstPageComponent中导航,而不要在HomeComponent中导航。我的HomeComponent包含以下代码:
<menu-app></menu-app>
<page-router-outlet></page-router-outlet>
<menu_bar-app></menu_bar-app>
我不能将数据放入此组件中,因为这些数据显示在所有组件中。
当我登录应用程序时,我的登录功能在/ home / fp中导航 当我保持登录状态时,我的应用程序打开/ home
当我保持登录状态时,我想在/ home / fp中导航。
HomeComponent具有:
<menu-app></menu-app>
<page-router-outlet></page-router-outlet>
<menu_bar-app></menu_bar-app>
FirstPageComponent具有:
<ActionBar title="Home" backgroundColor="#EE6E73" color="#FFFFFF">
<ActionItem android.position="true" [nsRouterLink]="['/home/profile']">
<img src="~/assets/images/male.png" width="30" height="30" stretch="aspectFit" padding='15' />
</ActionItem>
</ActionBar>
<GridLayout rows="*,60">
<ScrollView backgroundColor="#f1f1f1">
<StackLayout>
<label text="First Page"></label>
</StackLayout>
</ScrollView>
</GridLayout>
AuthGuard:
canActivate(): boolean {
if (this.auth.isAuthenticated()) {
return true;
}
this.router.navigate(['/login']);
return false;
}
你能问我任何想法吗?