2017-07-27 93 views
1

当我使用浏览器直接导航到路线时,应用程序重新引导,然后它将我带到正确的页面/组件。 当我通过一个按钮导航时,它会直接带我到那里,而无需重新启动应用程序。Angular 4路由器:直接浏览器导航重新启动应用程序

这是预期的行为? 我该如何预防?

问题是我们使用身份服务器进行身份验证。它需要一个回调url,它被视为直接浏览器导航,并且应用程序重新启动。

我们的应用程序,routing.module看起来是这样的:

const routes: Routes = [ 
    { path: '', redirectTo: '/dashboard', pathMatch: 'full' }, 
    { path: 'dashboard', component: DashboardComponent, canActivate: [RouteGuardService] }, 
    { path: 'users', component: UsersMainComponent}, 
    { path: 'vendors', component: VendorMainComponent}, 
    { path: 'invoices', component: InvoicesMainComponent}, 
    { path: 'offers' , component: EsdMainComponent}, 
    { path: 'settings' , component: SettingsMainComponent}, 
    { path: 'callback' , component: CallbackComponent}, 
    { path: 'createvendor' , component: CreateVendorsComponent, canActivate: [RouteGuardService]}, 
    { path: 'customerdashboard' , component: CustomerDashboardComponent}, 
]; 

@NgModule({ 
    imports: [RouterModule.forRoot(routes)], 
    exports: [RouterModule], 
    providers: [RouteGuardService] 
}) 
export class AppRoutingModule { } 

回调路径是身份服务器的回调URL。

+0

您是否找到任何解决方法? – Boris

回答

1

是的这是预期的行为。在Angular应用程序中使用按钮进行路由时,只需使用pushState即可修改历史记录as described in the docs(位于底部)。

当您执行直接导航时,您将获取index.html,这将启动应用程序,然后应用程序将使用当前URL来确定显示哪个组件。

The answer to this question希望涵盖如何解决您的问题。

+0

感谢您的有用信息。不幸的是,你提供给相关问题的链接没有帮助。 – hholtij

相关问题