[英]back button going back to login page instead of home page in angular 4
我在浏览器中按下后退按钮时遇到了奇怪的问题,当我单击登录页面时,我进入了登录页面。
在主页上,当我单击报告页面时,我具有菜单选项,例如报告和销售,然后转到报告页面。
我的问题是,当我单击报告页面上的浏览器后退按钮时,它会转到登录页面而不是主页
主页的URL:/ localhost:4200 / home
报告的URL页面:/ localhost:4200 / home / monthlyreport / my
而且我已经为下面的浏览器后退按钮编写了代码
import { PlatformLocation, Location } from '@angular/common'
constructor(private location: PlatformLocation, private loc: Location) {
location.onPopState(() => {
//window.history.back();
this.loc.back(); // tried with this one but no result
});
}
任何人都可以帮忙,如何使用angular 4返回上一页。非常感谢。
更新的登录操作方法
const routes: Routes = [
{
path: "",
redirectTo: "login",
pathMatch: "full"
},
{
path: "login",
component: LoginComponent
},
{
path: "error/:errorId",
component: ErrorComponent
},
{
path: "logout",
component: LogoutComponent
},
{
path: "home",
data: {
breadcrumb: "Home"
},
component: HomeComponent,
}
children: [
{
path: "monthlyreport/:type",
data: {
breadcrumb: "Reports"
},
component: MonthlyReportComponent,
canActivate: [AuthGuardService]
}
]
];
我相信您应该按照以下方式重写代码:
{
path: "home",
data: {
breadcrumb: "Home"
},
component: HomeComponent,
children: [
{
path: "monthlyreport/:type",
data: {
breadcrumb: "Reports"
},
component: MonthlyReportComponent,
canActivate: [AuthGuardService]
}
]
}
];
这将使对象的结构与此处Angular文档中使用的示例一致
const crisisCenterRoutes: Routes = [
{
path: 'crisis-center',
component: CrisisCenterComponent,
children: [
{
path: '',
component: CrisisListComponent,
children: [
{
path: ':id',
component: CrisisDetailComponent
},
{
path: '',
component: CrisisCenterHomeComponent
}
]
}
]
}
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.