Angular 2 url路径不起作用

标签 angular angular2-routing

我正在使用@RouteConfig 进行导航,路由配置就像

@RouteConfig([
{ path: '/calendar', name: 'Calendar', component: CalendarComponent }]}

当我使用诸如

的路由链接时,CarouselComponent 被加载
<a [routerLink]="['Calendar']">Calendar</a>

URL 路由到 http://localhost:60708/calendar

但是,当我想访问这个URL时http://localhost:60708/calendar 直接在地址栏输入网址或点击路由链接访问页面后点击F5(刷新页面),页面不再显示。

为什么会这样?如何使用 URL 路径加载组件?

最佳答案

感谢所有提供提示的评论。

主要是我根本没有配置定位策略。

在我配置 HashLocationStrategy 后它现在可以工作了

关于Angular 2 url路径不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34720502/

相关文章:

angular - 知道父级中选择了哪个子 RouteSegment 吗?

angular - 如何从模板访问当前的 FormControl

javascript - 如何在 Angular 中使用 Jquery 查询生成器

javascript - Angular2 当我刷新页面时,页面不会加载到路由器参数中

javascript - typescript 'is not a module' 错误

javascript - 如何在主路由中加载新路由

authentication - Angular2 auth guard 带有 http 请求和 observables

Angular 2 : How to provide interpolation with [routerLink]

Angular 2 : multiple HTML pages within same component

javascript - 表格数组 : Cannot find control with unspecified name attribute in angular6