Angular2在@ angular / router中找不到router_providers和locationstrategy

haa*_*i47 0 typescript angular-routing angular

我使用angular2路由器,但直接路径出现问题。如果我写localhost:3000/container 页面将找不到。我知道如果我包括ROUTER_PROVIDERS,那将是可行的。但是我没有ROUTER_PROVIDERS和locationstrategy

看我的屏幕

root.module.ts 模块画面 package.json package.json屏幕

pep*_*ght 5

删除旧的@ angular / router弃用的软件包时,将删除ROUTER_DIRECTIVES和ROUTER_PROVIDERS,因此您只需从模块中的导入行中删除它们即可。

至于HashLocationStrategy和LocationStrategy,它们是@ angular / common模块的一部分,因此您需要执行以下操作:

import { HashLocationStrategy, LocationStrategy } from '@angular/common';
Run Code Online (Sandbox Code Playgroud)

但是,如果您要启用哈希定位策略,则建议的最新方法是在路由初始化中简单地添加以下内容:

imports: [
    ...,
    RouterModule.forRoot(rootRoutes, { useHash: true })
]
Run Code Online (Sandbox Code Playgroud)