1. 1. 准备两个父路由组件
    2. 2. 在两个 父路由组件下创建两个子路由组件
    3. 3. 注册四个组件
    4. 4.app-routing.module.ts中注册写入
    5. const routes: Routes = [
    6. {
    7. path:'parent',
    8. component:ParentComponent,
    9. // redirectTo:'/welcome',
    10. children:[
    11. {
    12. path:'welcome',
    13. component:WelcomeComponent
    14. },
    15. {
    16. path:'setting',
    17. component:SettingComponent
    18. },
    19. {
    20. path:'**',
    21. redirectTo:'welcome'
    22. }
    23. ]
    24. },
    25. {
    26. path:'child',
    27. component:ChilldComponent,
    28. children:[
    29. {
    30. path:'plist',
    31. component:ProductlistComponent
    32. },
    33. {
    34. path:'pcate',
    35. component:ProductcateComponent
    36. },
    37. {
    38. path:'**',
    39. redirectTo:'plist'
    40. }
    41. ]
    42. },
    43. {
    44. path:'**',
    45. redirectTo:'parent'
    46. }
    47. ];
    48. 5. app.component.html中设置两个父路由的切换,并设置路由的位置
    49. <a [routerLink]="[ '/parent' ]">首页</a>
    50. <a [routerLink]="[ '/child' ]">商品</a>
    51. <router-outlet></router-outlet>
    52. 6.在首页组件中
    53. <div class="content">
    54. <div class="left">
    55. <!-- <a href="#">欢迎首页</a> -->
    56. <a [routerLink]="[ '/parent/welcome' ]">欢迎首页</a>
    57. <!-- <a href="#">系统设置</a> -->
    58. <a [routerLink]="[ '/parent/setting' ]">系统设置</a>
    59. </div>
    60. <div class="right">
    61. <router-outlet></router-outlet>
    62. </div>
    63. </div>
    64. 7.在商品路由中
    65. <div class="content">
    66. <div class="left">
    67. <!-- <a href="#">商品分类</a> -->
    68. <a [routerLink]="[ '/child/pcate', ]">商品分类</a>
    69. <!-- <a href="#">商品列表</a> -->
    70. <a [routerLink]="[ '/child/plist' ]">商品列表</a>
    71. </div>
    72. <div class="right">
    73. <router-outlet></router-outlet>
    74. </div>
    75. </div>
    76. 8.在公共样式中
    77. .content{
    78. width: 100%;
    79. height: 500px;
    80. padding: 10px;
    81. display: flex;
    82. .left{
    83. width: 200px;
    84. height: 500px;
    85. border-right: 1px solid #eee;
    86. }
    87. .right{
    88. flex: 1px;
    89. }
    90. a{
    91. display: block;
    92. padding: 10px 4px;
    93. }
    94. }