【发布时间】:2017-11-15 05:13:25
【问题描述】:
嗨,在我的应用程序中,如果我刷新它会转到主页,我需要避免这种情况并希望重定向到特定的所需路径,无法找到在路由或某处实现此功能的位置,谁能帮助我. 我的 app.component 文件
import {Component, OnInit} from '@angular/core';
import {Router, ActivatedRoute, Params} from "@angular/router";
import {AppService} from "../../services/app.service";
@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
islogin: boolean = true;
currentPage: string = '';
constructor(
private router: Router,
public appService: AppService
) {
}
ngOnInit() {
this.islogin = !this.islogin;
}
}
路由文件:
export const appRoutes: Routes = [
{
path: 'login',
component: LoginComponent
},
{
path: 'superuser-miscsuperusers',
component: miscsuperusersComponent
},
{
path: '**',
component: LoginComponent
},
{
path: 'clients',
component: ClientsComponent
}
];
export const appRoutingProviders: any[] = [];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes/*, { enableTracing: true }*/);
【问题讨论】:
-
添加你的应用路由文件
-
@Sravan 添加了我的路由文件
-
你从哪个路由刷新,因为如果你点击一个在路由中没有它的路由的页面,它会进入登录页面,就像你给的
path: '**' -
一般情况下,
path: '**'应该被重定向到任何未找到的页面 -
@Sravan 如果我从 'superuser-miscsuperusers' 路径刷新它将进入登录页面,我必须避免这种情况并希望重定向到我在路由文件中没有提到的 'client' 路径跨度>