简体   繁体   English

angular 在重建之前找不到模块

[英]angular can't find module untill rebuild

I have this very odd problem where i have the force my angular to "rebuild" (by changing something in the file and reloading the serve) Before my route can be reached我有一个非常奇怪的问题,我强制我的 angular “重建”(通过更改文件中的某些内容并重新加载服务)在到达我的路线之前

Here is my folder structure:这是我的文件夹结构:

在此处输入图像描述

app-routing.module.ts应用程序路由.module.ts

    import {NgModule} from '@angular/core';
import {PreloadAllModules, RouterModule, Routes} from '@angular/router';
import {redirectUnauthorizedTo, canActivate} from '@angular/fire/auth-guard';

const redirectUnauthorizedToLanding = redirectUnauthorizedTo(['/login/signin']);

    const routes: Routes = [
        {
            path: '',
            loadChildren: () => import('../login/login.module').then(m => m.LoginModule)
        },
        {
            path: 'dashboard',
            loadChildren: './dashboard/dashboard.module#DashboardPageModule',
            ...canActivate(redirectUnauthorizedToLanding)

        },
        {path: 'statistic', loadChildren: './statistic/statistic.module#StatisticPageModule'}


    ];

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

login-routing.module登录路由模块

    import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {AngularFireAuthModule} from "@angular/fire/auth";
import {ReactiveFormsModule} from "@angular/forms";

const routes: Routes = [
    {
        path: 'login',
        pathMatch: 'prefix',
        children: [
            {
                path: 'signin',
                loadChildren: './pages/sign-in/sign-in.module#SignInPageModule'
            },
            {
                path: 'signup',
                loadChildren: './pages/sign-up/sign-up.module#SignUpPageModule'
            },
        ]
    },
];

@NgModule({
    imports: [RouterModule.forChild(routes), AngularFireAuthModule, ReactiveFormsModule],
    exports: [RouterModule]
})
export class LoginRoutingModule {
}

Can anyone tell me whats going on?谁能告诉我发生了什么事?

When using the children property in the router config, there must be a nested <router-outlet> present.在路由器配置中使用children属性时,必须存在嵌套的<router-outlet> Otherwise, the route will exist (no errors in the console), but the component will not be rendered.否则,路由将存在(控制台中没有错误),但不会渲染组件。

Check my stackblitz demo查看我的 stackblitz演示

The login component has a router-outlet to render the routes defined in the children property. login 组件有一个router-outlet来呈现在children属性中定义的路由。 If you were to comment that out, you will see that the route is valid, but the sign-up component doesnt get rendered.如果您将其注释掉,您将看到该路由是有效的,但注册组件不会被呈现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM