角度 2.0.0-rc.1 如何配置路由器以像 UI-Router 一样运行



我正在尝试获取angular2路由器设置以支持深度链接。 我们曾经在 angular 1.5 中使用 ui-router,它将状态信息保留在"#"的右侧。 我试图了解是否可以配置@angular/路由器或@angular/路由器弃用的 Angular2 路由器以支持此行为。我找到了一些引用 HashLocationStrategy 的文档,但我无法从 @angular/路由器弃用或@angular/router 导入它,所以我不确定这些示例是否仍然有效。

深度链接角度2

演练

具体来说,我无法执行此导入:

import {LocationStrategy, HashLocationStrategry} from 'angular2/router';

你应该从'@angular/common'导入它:

主要.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

最新更新