我正在尝试使用angular2路由器设置来支持深层链接。我们曾经在角度1.5中使用ui-router,它将状态信息保存在'#'的右侧。我试图了解是否可以配置Angular2路由器@ angular / router或@ angular / router-deprecated以支持此行为。我找到了一些引用HashLocationStrategy的文档,但我无法从@ angular / router-deprecated或@ angular / router导入,所以我不确定这些示例是否仍然有效。
Deep Linking Angular2 walk through
具体来说,我无法进行此导入:
import {LocationStrategy, HashLocationStrategry} from 'angular2/router';
答案 0 :(得分:2)
您应该从' @ angular / common':
导入它main.ts:
import { bootstrap } from '@angular/platform-browser-dynamic';
import { ROUTER_PROVIDERS } from '@angular/router-deprecated';
import { provide } from '@angular/core';
import { LocationStrategy,
HashLocationStrategy } from '@angular/common';
import { AppComponent } from './app.component';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
provide(LocationStrategy,
{useClass: HashLocationStrategy})
]);
参考:https://angular.io/docs/ts/latest/guide/router-deprecated.html