在应用启动期间未评估Angular 8子模块中定义的路由

问题描述 投票:1回答:1

自升级到Angular 8后,我的SPA在使用给定哈希值加载整个应用程序时的行为有所不同。加载#/public/signup时,应用程序将重定向到#/trips/home

我的应用程序已模块化,而app.route.ts仅定义:

const routes: Routes = [
    { path: '', pathMatch: 'full', redirectTo: 'trips/home' },
    { path: '**', redirectTo: 'trips/home' },
];

export const AppRouting = RouterModule.forRoot( routes, {
    useHash: true
} );

然后定义public / public.route.ts

const publicRoutes: Routes = [
    {
        path: 'public',
        children: [
            { path: 'signup', component: SignupComponent },
            { path: 'about', component: AboutComponent },
            { path: 'privacy', component: PrivacyComponent },
            { path: 'terms', component: TermsComponent },
            { path: 'login', component: LoginComponent },
            { path: 'reset/:token', component: ResetComponent },
            { path: 'verify/:token', component: VerifyComponent },
            { path: 'forgotpassword', component: ForgotpasswordComponent },
            { path: 'logout', component: LogoutComponent },
        ]
    }
];

export const PublicRoutes = RouterModule.forChild( publicRoutes );

似乎正在进行一些延迟加载,因此在评估哈希值时,尚不知道/ public路径,并且我将全部重定向到'trips / home'。应用加载完毕后,所有路径都将正常运行。

PublicModule在app.module.ts中定义(急于加载)为>

@NgModule( {
    declarations: [AppComponent],
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        FlexLayoutModule,

        StateModule,
        CoreModule,
        SharedModule,
        PublicModule,
        StaticDataModule,
        ReportingModule,
        TripsModule,
        // register *after* feature modules and their routes!
        AppRouting,
        // required, even if the array is empty (see sub-modules for registered features)
        EffectsModule.forRoot( [] )
    ],
    exports: [ ],
    providers: [
        Title,
        { provide: LocationStrategy, useClass: HashLocationStrategy },
        { provide: APP_BASE_HREF, useValue: '/' }
    ],
    bootstrap: [AppComponent]
} )
export class AppModule { }

有人可以指出自Angular 7以来有关模块路由处理方式的变化吗?

自升级到Angular 8后,我的SPA在使用给定哈希值加载整个应用程序时的行为有所不同。加载#/ public / signup时,该应用程序将重定向到#/ trips / home。我的应用是...

angular angular-ui-router lazy-loading
1个回答
0
投票

不足为奇,原因根本不是Angular。对于遇到类似问题的人:

© www.soinside.com 2019 - 2024. All rights reserved.