ユーザーがログインした後、LoginPage を AccountPage に置き換えようとしていますが、タブを一番下に置いたままにしていますが、this.router.navigate(account) を使用すると、タブが完全に削除されます。
予期される動作: ユーザーがアカウント タブをクリックし、ユーザーがログインし、ログイン ページがユーザー アカウント ページに置き換えられます。以下は、予想される動作のスクリーンショットです。
- login-page.ts
login() {
if (this.loginForm.valid) {
this.loadingService.show();
this.userService.login(this.loginForm.value).subscribe(
(data: any) => {
this.loadingService.hide();
if (data.status === "success") {
let user = data.data;
this.storageService.setUser(user);
this.events.publish("user:logged", user);
this.openUserAccount(user.id, user);
} else {
this.alertService.present(data.message, data.status);
console.log(data.message, data.status )
}
},
() => {
this.loadingService.hide();
this.toastService.showGenericError();
}
);
}
}
openUserAccount(id: string, user: User){
this.dataService.setData(id, user);
this.router.navigate(["/account", id]);
}
- tabs.page.ts
tabs: any[] = [
{
name: "novelties",
icon: "icon-novelties"
},
{
name: "pratos",
icon: "icon-menus" },
{
name: "account",
icon: "icon-user"
},
{
name: "stores",
icon: "icon-stores"
},
{
name: "about",
icon: "icon-qrcode"
}
];
- tabs-routing.module.ts
const routes: Routes = [
{
path: "tabs",
component: TabsPage,
children: [
{
path: "novelties",
children: [
{
path: "",
loadChildren: () => import("@pages/novelties/novelties.module").then(m => m.NoveltiesPageModule)
}
]
},
{
path: "pratos",
children: [
{
path: "",
loadChildren: () => import("@pages/pratos/pratos.module").then(m => m.PratosPageModule)
}
]
},
{
path: "account",
children: [
{
path: "",
loadChildren: () => import("@pages/login/login.module").then(m => m.LoginPageModule)
}
]
},
{
path: "stores",
children: [
{
path: "",
loadChildren: () => import("@pages/stores/stores.module").then(m => m.StoresPageModule)
}
]
},
{
path: "about",
children: [
{
path: "",
loadChildren: () => import("@pages/about/about.module").then(m => m.AboutPageModule)
}
]
},
{
path: "",
redirectTo: "/tabs/novelties",
pathMatch: "full"
}
]
},
{
path: "",
redirectTo: "/tabs/novelties",
pathMatch: "full"
}
];