我有一个角度项目,我想要链接到其他页面上的书签。所以在我的html中,我有这样的链接:
<a href="#products" routerLink="overview">products</a>但是当页面编译并运行时,我看到这个链接被重写为如下内容:
<a _ngcontent-kfm-c5="" href="/overview/overview" routerlink="overview" ng-reflect-router-link="overview">products</a>链路不工作的明显效果。
在app-router.module.ts中,路由定义为
{ path: 'main', component: MainComponent },
{ path: 'overview', component: OverviewComponent },
{ path: '', redirectTo: '/main', pathMatch: 'full' },
{ path: '**', component: MainComponent }它以前工作得很好。
这是预期的行为吗?我是不是遗漏了什么?我有较旧的项目,使用类似的链接,工作良好。或者这是一个angular-router bug?我的angular-core是7.2.0,我的angular路由器是7.2.15。任何指针都非常感谢,因为我被困在这里调试。
发布于 2019-05-14 22:59:02
在单页应用程序中,routerLink会将组件加载到路由器出口,而无需重新加载/刷新页面。另一方面,单击href链接将刷新/重新加载整个应用程序,或者将应用程序重置回启动状态(状态将被重置)。
您不应该同时使用这两种方法,否则它们将无法正常工作。
https://stackoverflow.com/questions/56133286
复制相似问题