重定向不会改变 angular 中的视图 4

redirection doesn't change view in angular 4

我是 angular 的新手,我不知道如何正确重定向。我在 stackblitz 中做了这个简单的页面来测试它,但我的重定向效果不佳,因为 html 的信息没有改变。我有什么错?

https://stackblitz.com/edit/angular-2bxumx?file=app%2Fpage1%2Fpage1.component.html

您的 html 缺少路由器插座标签...并且还需要添加默认路由:

请注意,如果您在 app.compontne.ts 中添加以下行,您的 page1 将在点击时加载:

<router-outlet></router-outlet>

Asso,记得设置默认路由,这样当您的应用加载时,路由器就会显示一些内容:

const appRoutes: Routes = [  
  { path: '', redirectTo: 'hello', pathMatch: 'full' },
  { path: 'hello', component: HelloComponent },
  ...
];

我建议您至少看一下 navigation 上的文档。