当使用路由子路由it does not load the component due to the nature of the component
重新加载页面时,它甚至不会路由回主路由。首先,这应该由我处理还是由角度照顾?
更新:
Hashstrategy没有按照第二个问题的预期方式工作。
如果是第一个,我有路由/users/...
和孩子/users/vote
。当重新加载/users
时,它会转到/login
,但是当重新加载/users/vote
时,它不会重新加载到该组件(自然地),也不会转到/ login
更新
@RouteConfig([
{path: '/vote', component: VoteComponent, name: 'VoteCmp',useAsDefault: true },
{path: '/getapproval', component: GetapprovalComponent, name: 'GetapprovalCmp' },
{path: '/userresults', component: ResultsComponent, name: 'UserresultsCmp' }
])
@Component({
selector: 'users',
....
directives: [ROUTER_DIRECTIVES, RouterLink]
})
export class UsersComponent{
constructor(private _userdetails: Userdetails, private _router: Router){
if (this._userdetails.usertypeDetails() === "" || this._userdetails.isLoggedin() === false){
this._router.navigate( ['HomeCmp'] );
}
if(this._userdetails.usertypeDetails() === 'admin'){
this._router.navigate( ['AdminCmp'] );
}
}
}
我的投票组件
@Component({
selector: 'vote',
template: `<div>Vote Component</div>`,
})
export class VoteComponent {
constructor(private _userdetails: Userdetails, private _router: Router){
if (this._userdetails.usertypeDetails() === "" || this._userdetails.isLoggedin() === false){
this._router.navigate( ['HomeCmp'] );
}
if(this._userdetails.usertypeDetails() === 'admin'){
this._router.navigate( ['AdminCmp'] );
}
}
}
我的boot.ts有这个
bootstrap(MainComponent,[Userdetails,ROUTER_PROVIDERS, Location, provide(LocationStrategy, {useClass: HashLocationStrategy}, ROUTER_BINDINGS, bind(APP_BASE_HREF).toValue('/')]);
答案 0 :(得分:3)