Angular 2 - 我的子路由不会打开任何东西
创始人
2024-10-15 13:31:07
0

要解决Angular 2中子路由无法打开的问题,可以按照以下步骤进行:

  1. 首先,确保在父组件的模板中使用标签来显示子路由的内容。

  1. 在父组件的路由配置中,添加子路由的配置。
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { ParentComponent } from './parent.component';
import { ChildComponent } from './child.component';

const routes: Routes = [
  { path: 'parent', component: ParentComponent, 
    children: [
      { path: 'child', component: ChildComponent }
    ]
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class ParentRoutingModule { }
  1. 确保在父组件的模板中使用routerLink指令来导航到子路由。
Go to Child
  1. 确保在父组件的模块中导入和声明子组件。
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { ParentComponent } from './parent.component';
import { ChildComponent } from './child.component';
import { ParentRoutingModule } from './parent-routing.module';

@NgModule({
  imports: [
    CommonModule,
    ParentRoutingModule
  ],
  declarations: [
    ParentComponent,
    ChildComponent
  ]
})
export class ParentModule { }
  1. 如果子路由仍然无法打开,请检查子组件的路径是否正确,并确保在父组件的路由配置中指定了正确的路径。

希望这些步骤可以帮助您解决Angular 2中子路由无法打开的问题。如果问题仍然存在,请提供更多的代码和错误信息,以便更好地帮助您解决问题。

相关内容

热门资讯

日前!哈局辅助作必弊,wejo... 日前!哈局辅助作必弊,wejoker辅助脚本(透视)果然真的是有辅助工具(哔哩哔哩)1、上手简单,内...
透视曝光"aapok... 透视曝光"aapoker发牌逻辑"真是是真的辅助器(哔哩哔哩)1、首先打开aapoker发牌逻辑辅助...
透视专业"哈糖大菠萝... 透视专业"哈糖大菠萝怎么挂"切实存在有辅助挂(哔哩哔哩)1、下载好哈糖大菠萝怎么挂正确养号方法之后点...
反观!wepoker辅助工具,... 反观!wepoker辅助工具,wepoker好友助力码(透视)总是有辅助app(哔哩哔哩)1、玩家可...
透视关于"德普之星透... 透视关于"德普之星透视辅助插件"一贯有辅助神器(哔哩哔哩)1、点击下载安装,德普之星透视辅助插件脚本...
据相关数据显示!hhpoker... 据相关数据显示!hhpoker挂免费辅助器,哈糖大菠萝有挂吗(透视)都是有辅助教程(哔哩哔哩)1、h...
透视开挂"德州局脚本... 透视开挂"德州局脚本"其实真的有辅助app(哔哩哔哩)1、德州局脚本透视辅助软件激活码多个强度级别选...
出现新变化!小逸碰胡辅助器,w... 出现新变化!小逸碰胡辅助器,wejoker黑侠辅助器(透视)好像是有辅助技巧(哔哩哔哩)1、下载好小...
透视了解"wepok... 透视了解"wepoker辅助器如何使用"真是是有辅助方法(哔哩哔哩)一、wepoker辅助器如何使用...
刚刚!小程序多乐跑得辅助,we... 刚刚!小程序多乐跑得辅助,wepoker辅助真的假的(透视)切实真的是有辅助教程(哔哩哔哩)进入游戏...