Angular2重定向到默认页面
问题描述:
我想重定向时刷新page.Before刷新页面我是默认页这里http://localhost/mypage/#/brand,当我刷新页面 我想重定向http://localhost/mypage/#/homeAngular2重定向到默认页面
const appRoutes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: Home },
{ path: 'brand', component: BrandCP },
];
export const appRoutingProviders: any[] = []
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes, { useHash: true});
答
使用查询字符串如?redirect=1
当你走这brand
页面只是追加值重定向手风琴到您的偏好你想在下一次重新加载然后在品牌的组件只是少于这个重定向查询参数的价值,如果它是未定义或设置为零,然后让他留在页面上,如果它被设置为1,则将其重定向到主页简单且简单