简体   繁体   English

Angular 2 NgMdoule和延迟加载路由问题

[英]Angular 2 NgMdoule and Lazy Loaded Routing Issue

I am using Angular2 Rc5 in my application and stuck in routing with NgModule. 我在我的应用程序中使用Angular2 Rc5,并被NgModule阻塞。

I have one module in my application called product module (lazy loaded module) with two components called productListComponenent and ProductDetailComponenet. 我的应用程序中有一个模块,称为产品模块(延迟加载的模块),其中有两个组件分别称为productListComponenent和ProductDetailComponenet。 I also have a welcome page. 我也有一个欢迎页面。

When I run the application welcome page appears and from there I can navigate to a product page and from there after clicking on any product I can navigate to product detail page. 当我运行应用程序时,将出现欢迎页面,从那里我可以导航到产品页面,单击任何产品后都可以从那里导航到产品详细信息页面。

The problem I am facing is I can not directly navigate to ProductDetail page. 我面临的问题是我无法直接导航到ProductDetail页面。 eg I can not browse this URL. 例如,我无法浏览该URL。

http://localhost:58248/products/1

My code for routing as follows. 我的路由代码如下。

app.routing.ts 应用程序路由

import { Routes, RouterModule } from '@angular/router';

const appRoutes: Routes = [
    { path: '', redirectTo: 'home', pathMatch: 'full' },
    { path: 'products', loadChildren: 'app/products/product.module' }
];

export const appRoutingproviders: any[] = [];

export const routing = RouterModule.forRoot(appRoutes);

product.routing.ts 产品路由

import { Routes, RouterModule } from '@angular/router';

import { ProductListComponent } from './product-list.component';
import { ProductDetailComponent } from './product-detail.component';



 const appRoutes: Routes = [
    { path: '', component: ProductListComponent},
    { path: ':id', component: ProductDetailComponent },
    ];

export const routing = RouterModule.forChild(appRoutes);

when I directly browse the detail URL It gives me an error. 当我直接浏览详细URL时,它给我一个错误。 Please refer to the attached image 请参考所附图片

在此处输入图片说明 .

If you are using RC5 make sure you use a slash in base tag not . 如果您使用的是RC5,请确保在基本标记not中使用斜杠。 which was belong to previous RC versions 属于以前的RC版本

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

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