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

Angular2 cannot find router_providers, locationstrategy in @angular/router

我使用 angular2 路由器并遇到直接路径问题。 如果我写 localhost:3000/container 将找不到页面。我知道如果我包含 ROUTER_PROVIDERS 它将起作用。但是我没有 ROUTER_PROVIDERS 和 locationstrategy

看看我的屏幕

root.module.ts package.json

ROUTER_DIRECTIVES 和 ROUTER_PROVIDERS 在删除旧的 @angular/router-deprecated 包时被删除,因此您可以从模块的导入行中删除它们。

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

import { HashLocationStrategy, LocationStrategy } from '@angular/common';

但是,如果您想启用哈希位置策略,最新推荐的方法是简单地将以下内容与路由初始化一起使用:

imports: [
    ...,
    RouterModule.forRoot(rootRoutes, { useHash: true })
]