简体   繁体   English

Angular 2 url路径无法正常工作

[英]Angular 2 url path is not working

I am using the @RouteConfig for navigation and the route config is like 我使用@RouteConfig进行导航,路由配置就像

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

The CarouselComponent is loaded when I use route link such as 当我使用诸如的路由链接时加载CarouselComponent

<a [routerLink]="['Calendar']">Calendar</a>

and the URL routes to http://localhost:60708/calendar 并且URL路由到http:// localhost:60708 / calendar

However, when I would like to visit the URL http://localhost:60708/calendar directly by typing the URL in the address bar or to click F5 (Refresh page) after visit the page by clicking the route link, the page does not show any more. 但是,当我想通过在地址栏中输入URL直接访问URL http:// localhost:60708 / calendar ,或者通过单击路由链接访问页面后单击F5(刷新页面),页面不会再显示一下。

Why does this happen? 为什么会这样? How can I use the URL path to load the component? 如何使用URL路径加载组件?

Thanks for all comments providing the hints. 感谢所有提供提示的评论。

The main reason is that I did not configure the location strategy at all. 主要原因是我根本没有配置位置策略。

It is working now after I configured the HashLocationStrategy 在我配置HashLocationStrategy之后它现在正在工作

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

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