单击链接后,URL会更改,但不会开始导航

时间:2016-07-18 12:36:38

标签: angular router ngrx

我刚刚从angular2的路由器转移到ngrx的路由器。 另外,我使用的是角度2 rc4。

我的路线看起来像这样:

export const: Routes = [
    {path: "appRoute1", component: "appComponent1", guards: [HashGuard, hasSelectedGuard]},
    {path: "appRoute2", component: "appComponent2", guards: [HashGuard, hasSelectedGuard]},
]

HashGuard只有一个函数(和构造函数):

protectRoute(candidate : TravesalCandidate){
    if (!window.location.hash){
        this.router.go(HOME_ADDRESS);
    }
    return Observable.of(true);
}

同样,HasSelectedGuard只有一个功能:

protectRoute(candidate : TravesalCandidate){
   if (!this.currentSelectionService.hasSelectedPerson()){
       this.router.go(HOME_ADDRESS);
       return Observable.of(false);
   }
   return Observable.of(true)
}

我正在引导所需的一切,正如我应该的那样:

bootstrap(AppComponent, [
    provideRouter(routes, HashLocationStrategy), 
    Router, 
    HashGuard, 
    CurrentSelectionService
]

我有一个带有多个链接的sidemenu组件,其他我有appRoute1和appRoute2:

<a [linkTo]="'/appRoute1'"> ... </a>
<a [linkTo]="'/appRoute2'"> ... </a>

当我点击其中一个链接时,URL会按预期更改,但页面本身不会加载(点击后没有请求发送,组件的构造函数不是

非常感谢帮助。

1 个答案:

答案 0 :(得分:0)

我最终恢复到Angular的组件并使用next

在撰写本文时,NgRX的路由器仍然不合适。

相关问题