嵌套路由不加载其组件并且不路由到主路由
nested route does not load its component and does not route to main route
当使用路由 child 路由 it does not load the component due to the nature of the component
重新加载页面时,它甚至没有路由回主路由。首先,这应该由我处理还是由 angular 处理?
更新:
Hashstrategy 没有按照第二个问题的预期方式工作。
如果是第一个,我有路线 /users/...
和 child /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('/')]);
如评论中所述,APP_BASE_HREF
和嵌套路由(可能是 issue #5782)存在错误。
解决方案(目前)是将 base 标签添加到 main html:
<base href="/">
当使用路由 child 路由 it does not load the component due to the nature of the component
重新加载页面时,它甚至没有路由回主路由。首先,这应该由我处理还是由 angular 处理?
更新:
Hashstrategy 没有按照第二个问题的预期方式工作。
如果是第一个,我有路线 /users/...
和 child /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('/')]);
如评论中所述,APP_BASE_HREF
和嵌套路由(可能是 issue #5782)存在错误。
解决方案(目前)是将 base 标签添加到 main html:
<base href="/">