首页 文章

angular 2.0.0-rc.1如何配置路由器的行为就像UI-Router那样?

提问于
浏览
0

我正在尝试使用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';

1 回答

  • 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

相关问题