This question already has answers here:
Angular2 Exception: Can't bind to 'routerLink' since it isn't a known native property
                                
                                    (12个答案)
                                
                        
                                3年前关闭。
            
                    
当我尝试添加hashlocationstrategy时发生此错误

引导程序

///<reference path="../typings/browser.d.ts"/>

import { bootstrap } from "angular2/platform/browser";
import { RootComponent } from "./root.component";
import { ROUTER_PROVIDERS, ROUTER_DIRECTIVES, LocationStrategy, HashLocationStrategy} from "angular2/router";
import { PLATFORM_DIRECTIVES, provide, enableProdMode } from "angular2/core";
import { HTTP_PROVIDERS } from "angular2/http";
import { FirebaseService } from "./shared/firebase.service";
import { Environment } from "./config/environment";

if (Environment === "production") {
  enableProdMode();
}


bootstrap(RootComponent, [
  FirebaseService,
  ROUTER_PROVIDERS,
  HTTP_PROVIDERS,
  provide(
    [PLATFORM_DIRECTIVES, {useValue: [ROUTER_DIRECTIVES], multi: true}],
    [LocationStrategy, {useClass: HashLocationStrategy}]
  )
])
  .catch(err => console.error(err));


考虑一下是因为我同时使用平台指令和locationstrategy的语法是错误的。有什么线索吗?

最佳答案

provide()PLATFORM_DIRECTIVES都需要单独的LocationStrategy

bootstrap(RootComponent, [
  FirebaseService,
  ROUTER_PROVIDERS,
  HTTP_PROVIDERS,

  provide(PLATFORM_DIRECTIVES, {useValue: ROUTER_DIRECTIVES, multi: true}),
  provide(LocationStrategy, {useClass: HashLocationStrategy})

  .catch(err => console.error(err));

10-04 15:22