我目前正在使用TypeScript处理Angular2项目,并且无法让HashLocationStrategy工作。我重写LocationStrategy在引导它在这里解释道:我创建了一个plunker来证明我的问题就在这里https://angular.io/docs/ts/latest/guide/router.htmlHashLocationStrategy不按预期方式工作
import {bootstrap} from 'angular2/platform/browser';
import {ROUTER_PROVIDERS} from 'angular2/router';
import {AppComponent} from './app.component';
// Add these symbols to override the `LocationStrategy`
import {provide} from 'angular2/core';
import {LocationStrategy,
HashLocationStrategy} from 'angular2/router';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
provide(LocationStrategy,
{useClass: HashLocationStrategy})
]);
:https://plnkr.co/edit/YE5w4iky53SHRi211lqX?p=preview
有其他人遇到这个问题?我误解了这个还是错过了一些东西?
编辑:预期的结果是路由在URL中使用散列。在应该产生这样一个网址的例子中:... /#/ fubar,而是我得到.../fubar
要查看生成的url,必须在单独的窗口中运行plunker全屏按钮)
什么是“不能让......上班”呢?什么是预期的行为?什么是实际行为?任何错误消息? –
对我来说,你的plunkr工作。我唯一的评论是,你在引导程序和组件中定义了两次'ROUTER_PROVIDERS' ... –