【问题标题】:Angular2 Lazy loading not displaying data but loading htmlpage in NetworkAngular2延迟加载不显示数据但在网络中加载htmlpage
【发布时间】:2023-04-09 21:52:02
【问题描述】:

Angular2 LazyLoading 当我点击 Link its Loading Its component,Htmlpages,Modules 但在 <router-outlet> 中不显示 Html 页面

母版页

<a [routerLink]="['Customer/Add']">Customer</a><br />
<a [routerLink]="['Employee/Add']">Employee</a><br />
    <router-outlet>
    </router-outlet>

客户组件

import { Component } from "@angular/core"    
@Component({
     templateUrl: '../../ui/customer/customer.html'
})
export class CustomerComponent {

}

客户模块

@NgModule({
    imports: [RouterModule.forChild(CustomerRoute), ReactiveFormsModule, CommonModule, ReactiveFormsModule, FormsModule, HttpModule],
    declarations: [CustomerComponent],
    bootstrap: [CustomerComponent]
}) 
export class CustomerModule {    
}

客户路线

import { Component } from "@angular/core"
import { CustomerComponent } from "../components/customer/customercomponent"

export const CustomerRoute = [
    { path: "Add", Component: CustomerComponent}
    ]

主路由

import { Component } from "@angular/core"
import { Routes } from "@angular/router"
import { HomePageComponent } from "../components/homepage/homepage"
export const ApplicationRoutes= [
    { path: '', component: HomePageComponent },
    { path: 'UI/MasterAngularPage.html' ,component: HomePageComponent },
    { path: 'Customer', loadChildren: '../modules/customermodule/customermodule#CustomerModule'},

]

【问题讨论】:

    标签: angular2-routing angular4-router


    【解决方案1】:

    使用以下代码重定向添加路由。

    export const CustomerRoute = [
        { path: "", redirectTo: "Add", pathMatch:"full"},
        { path: "Add", Component: CustomerComponent}
    ]
    

    从 CustomerModule 中删除引导代码。

    @NgModule({
        imports: [RouterModule.forChild(CustomerRoute), ReactiveFormsModule, CommonModule, ReactiveFormsModule, FormsModule, HttpModule],
        declarations: [CustomerComponent]
    }) 
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-04
      • 1970-01-01
      • 2016-08-12
      • 2017-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多