简体   繁体   English

使用导航菜单angular 2设置路线

[英]setting up routes with navigation menu angular 2

I have a tab menu and i set up my routes in my app.module.ts but i am not sure how to bridge between my tabs and my routes appropriately. 我有一个选项卡菜单,并且在app.module.ts中设置了路由,但是我不确定如何在选项卡和路由之间进行适当的桥接。

here is my tab html: 这是我的标签html:

<tabs>
    <tab [tabTitle]="'Home Page'">
    </tab>
    <tab tabTitle="Feedback"> </tab>
    <tab tabTitle="Background"> </tab>
    <tab tabTitle="What we do"> </tab>
</tabs>

my routes in app.module.ts: 我在app.module.ts中的路线:

const appRoutes: Routes = [
  { path: './app/homepage/homepage.component.html', component: AppComponent },
  { path: './app/feedback/feedback.component.html', component: FeedbackComponent },
  { path: './app/background/background.component.html', component: BackgroundComponent },
  { path: './app/whatwedo/whatwedo.component.html', component: WhatwedoComponent}
];

What are the steps i need to take to link the tabs with the correct route link. 我需要执行哪些步骤才能将选项卡与正确的路线链接相链接。

follow this example from this page https://material.angular.io/ 请遵循此页面上的示例https://material.angular.io/

here 这里

    <li *ngFor="let component of category.items">
      <a [routerLink]="['/components/component/', component.id]"
         routerLinkActive="docs-component-viewer-sidenav-item-
  selected">
        {{component.name}}
      </a>
    </li>

one key point is 一个关键点是

[routerLink]="['/components/component/', component.id]"

ante router will look like this ante路由器将如下所示

  {
    path: 'components',
    component: ComponentSidenav,
    children: [

    {path: 'components/:id', component: ComponentViewer},
    ],
   },

notice that the component that the parent and the child component have absolute paths, it will work 注意,父组件和子组件具有绝对路径的组件将正常工作

In your tab yo need to provide link on lcick of which it will show the licked component in the router outlet. 在您的标签中,您需要在lcick上提供链接,该链接将显示路由器出口中被舔掉的组件。

Make sure to add a tag <router-outlet></router-outlet> in your index.html so that routing component will be loaded there 确保在index.html中添加标签<router-outlet></router-outlet> ,以便将路由组件加载到此处

below will be your tab navigation 以下是您的标签导航

<tabs>
    <tab [tabTitle]="'Home Page'">
    </tab>
    <tab tabTitle="Feedback"><a [routerLink]="['./app/homepage/homepage.component.html]"
         routerLinkActive="css-class-for-active-link">
        Home
      </a></tab>
    <tab tabTitle="Background"> </tab>
    <tab tabTitle="What we do"> </tab>
</tabs>

Then on click of the Home link, it will load the home component inside <router-outlet></router-outlet> tag 然后单击Home链接,它将在<router-outlet></router-outlet>标签内加载home组件。

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

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