2016-08-17 162 views
1

使用Angular 2 Router。我有一个2级路由(root routingchild routing]页面重新加载子路由

我的问题是,导航到一个孩子路线时被加载后孩子被重新加载页面。

子级路由

const childRoutes: Routes = [ 
    { 
    path: '', 
    component: BaseComponent, 
    children: [ 
      { 
      path: '', 
      component: DetailsComponent 
      }, 
      { 
       path: 'other', 
       component: OtherComponent 
      } 
     ] 
    } 
]; 

export const childRouting = RouterModule.forChild(childRoutes); 

顶级路由

const appRoutes: Routes = [ 
    { 
     path: '', 
     redirectTo: '/overview', 
     pathMatch: 'full'}, 
    { 
     path: 'overview', 
     component: OverviewComponent}, 
    { 
     path: 'sub', 
     //This is the module which the childRoutes belongs to. 
     loadChildren: 'app/components/sub.module#SubModule' 
    } 
]; 

export const appRoutingProviders: any[] = []; 

export const routing = RouterModule.forRoot(appRoutes); 

从DetailsComponent

呼吁导航
export class DetailsComponent implements OnInit { 
    constructor(private router: Router) { } 

    ngOnInit() { } 

    onSubmit() { 
     this.router.navigate(['/sub/other']) 
    } 
} 

P.S

我试图让这个问题的短,所以如果需要更多的代码,那么请让我知道,我会很乐意加入。

+0

你是什么意思的“页面重新加载”。我从来没有看到路由器重新加载页面。它只添加/删除组件并更新浏览器URL栏中的URL。 –

+0

这就是为什么我很困惑。整页重新加载。完整的xhr电话,获取所有js文件,照片和所有内容。页面是空白的..有角度js的加载指示器,然后子视图重新出现。我能够导航到我想要的页面,但接着又有另一个http调用到同一页面。我会尝试记录屏幕并将其作为gif附加 – royB

+0

应该指向子路由的链接的URL是什么? (当鼠标移动到链接上时,工具栏中的chrome会显示什么) –

回答

相关问题