- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在应用程序中有以下路线。这里的问题是,如果我导航说 getEmp-by-id 或 page-not-found 并点击刷新,那么应用程序将登陆 app-home。但我希望它保持在刷新被点击的同一页面上。我没有实现任何 RouteGuards,简单的导航。有什么方法可以实现这一目标。
const appRoutes: Routes = [
{path: '', component: HomeComponent, children: [
{path: 'app-home', component: AppHomeComponent, resolve: {ApphomeResolver : AppHomeResolver}},
{path: 'getEmp-by-id', component: EmpComponent},
{path: 'page-not-found', component: pageNotFoundComponent},]
},
{path: '**', redirectTo: 'page-not-found', pathMatch: 'full'}
];
export class EmpComponent implements OnInit {
constructor(private router: Router, private route: ActivatedRoute, private alertService: AlertService, private employeeService: EmployeeService) { }
ngOnInit() {}
onSubmit() {
this.employeeService.getEmployee(empId).subscribe(
(data) => {
var responseCode = JSON.parse(data).responseCode;
var responseMessage = JSON.parse(data).responseMessage
if (responseCode === 200) {
this.router.navigate(['../emp-details'], { relativeTo: this.route });
} else {
this.router.navigate(['../page-not-found'], { relativeTo: this.route });
}
}, error => {
this.router.navigate(['../page-not-found'], { relativeTo: this.route });
});
} else {
this.alertService.error("Error");
}
}
}
最佳答案
处理页面刷新的一种方法是使用散列路由。要实现这一点,请在 app.module.ts 中编写以下代码:
import { APP_BASE_HREF, LocationStrategy, HashLocationStrategy } from '@angular/common';
@NgModule({
......
providers: [
{ provide: APP_BASE_HREF, useValue: '', }
, { provide: LocationStrategy, useClass: HashLocationStrategy }
.....
]})
export class AppModule {
}
请注意,这会将 # 添加到您的 route 。
关于javascript - Angular 5 页面刷新总是登陆首页而不是在同一页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49700466/
下午好试图在我着陆时做出响应式背景,但出于某种原因我不能我试图使用 height: auto, height: 100% 和 margin: 0 auto;高度 100% 有效,但它没有覆盖到我的屏幕
我正在为 Rails 应用程序创建启动页面,其中包含一个电子邮件字段供用户填写并在网站完全启动时收到通知。 最好的方法是什么? 我应该为着陆页创建一个新的应用程序还是我应该使用同一个应用程序并设置一些
按照 官方教程 ,下载安装包,点击安装后,如需在命令行启动,还需设置命令路径: 在命令行中,打开配置文件 .bash_profile: vim ~/.bash_profile 在最后一行加上:
1、登录数据库,在数据库中创建表user00,并且插入数据。 表的字段分别为: id(编号)、name(姓名)、grid(级别)、score(积分)、password(密码)、age(年龄)、
我是 cocoa 开发的新手。 当我使用 Storyboard在 Xcode 上创建一个新项目时,它使用我更喜欢的 iOS 模型,即拥有一个 viewController 和一个委托(delegate
我是一名优秀的程序员,十分优秀!