return Json(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = retData }, JsonRequestBehavior.AllowGet);
当我尝试访问“/ main / rahul”URL时,其中rahul是slug,未加载Second Child组件。而是在Web控制台中,我看到了一个错误列表,如
import { RouterConfig } from '@angular/router';
import { MainComponent } from './main.component';
import { FirstChildComponent } from './first-child.component';
import { SecondChildComponent } from './second-child.component';
export const TempRoutes: RouterConfig = [
{
path: 'main',
component: MainComponent,
children: [
{ path: ':slug', component: SecondChildComponent },
{ path: '', component: FirstChildComponent }
]
}
];
Angular Router版本:3.0.0-alpha.7
此外,当尝试访问URL:'/ main /'时,给出了与上面相同的错误,而它应该加载First Child Component。
答案 0 :(得分:0)
注意:请确保在MainComponent
,您已使用或放置<router-outlet>
。
我尝试做同样的事情并且工作正常,
请检查此实例,并尝试查看代码中是否有任何错误,
https://plnkr.co/edit/AYhau1gLYC7Flt4NknWa?p=preview
<强> app.approutes.ts 强>
import { provideRouter, RouterConfig } from '@angular/router';
import { HomeComponent } from './home.component';
import { MainCompnent } from './main.component';
import {UserComponent} from './user.component';
import {FirstChildComponent} from './firstChildComponent';
import {SecondChildComponent} from './secondChildComponent'
export const routes: RouterConfig = [
{ path: '', component: HomeComponent },
{ path: 'home', component: HomeComponent },
{ path: 'main',
component: MainCompnent,
children: [
{ path: ':slug', component: SecondChildComponent },
{ path: '', component: FirstChildComponent }
]
},
{ path: 'user', component: UserComponent }
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];