嵌套路由不会加载其组件,也不会路由到主路由

时间:2016-02-25 11:44:53

标签: angular parent-child reload router

当使用路由子路由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('/')]);

1 个答案:

答案 0 :(得分:3)

正如评论中所提到的,APP_BASE_HREF和嵌套路线(可能是issue #5782)存在错误。

解决方案(目前)是将基本标签添加到主html:

<base href="/">