【问题标题】:How to navigate from one page to another in angular2如何在angular2中从一页导航到另一页
【发布时间】:2017-12-14 13:46:47
【问题描述】:

我是 angular2 的新手。如何在 angular2 中从一页导航到另一页?我为此使用路由器插座。它只是在一个组件之间重定向到另一个组件,但是当我单击下拉项时,我想从主页重定向到另一个组件。我需要为此使用 page-router-outlets 吗?如果是这样,如何使用它以及如何安装 nativescript 等等。提前感谢您的回复。

【问题讨论】:

标签: angular2-routing


【解决方案1】:

我正在使用 app.route.ts

import { Routes } from '@angular/router';
import { HomeComponent } from './home.component';
import { AboutComponent } from './about.component';

export const routes: Routes = [
  { path: 'home' ,  component: HomeComponent,pathMatch: 'full' },
  { path: 'about',  component: AboutComponent }
];

在 app.component.html 我有

<ul>
<li id="home"><a [routerLink]="['/home']" >Home</a> </li>
<li id="about"><a  [routerLink]="['/about']" >About</a></li>
</ul>
<router-outlet></router-outlet>

在 app.module.ts 我已经配置了路由器。 当我单击主页超链接时,它将仅路由到 app.component.html 页面。它不会重定向到另一个页面,每次我进入新页面时,app.component.html 总是显示在页面顶部。 如何路由到新页面而不在新页面中显示 app.component.html。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-08
    • 1970-01-01
    • 2023-03-12
    • 2020-08-13
    • 2013-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多