Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location and HashLocationStrategy stopped working in beta.16

Tags:

angular

Error message

VM556 angular2-polyfills.js:349Error: Token must be defined!(…)

or

error TS2305: Module '"/node_modules/angular2/router"' has no exported member 'LocationStrategy'.
error TS2305: Module '"/node_modules/angular2/router"' has no exported member 'HashLocationStrategy'.
error TS2305: Module '"/node_modules/angular2/router"' has no exported member 'Location'.

How to fix

like image 750
Günter Zöchbauer Avatar asked Apr 26 '16 10:04

Günter Zöchbauer


1 Answers

update >= rc.5

@NgModule({
  providers: [{ provide: LocationStrategy, useClass: HashLocationStrategy}]
})
export class AppModule {}

update >= rc.0

import {  
  PlatformLocation,  
  Location,  
  LocationStrategy,  
  HashLocationStrategy,  
  PathLocationStrategy,  
  APP_BASE_HREF}  
from '@angular/common';  

import {BrowserPlatformLocation} from   '@angular/platform-browser';

original

Change

import {ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy} from 'angular2/router';

to

import {ROUTER_PROVIDERS} from 'angular2/router';
import {LocationStrategy, HashLocationStrategy} from 'angular2/platform/common';

See also
- https://github.com/angular/angular/issues/8229

Full list of moved exports:
- https://github.com/angular/angular/pull/8230/files

import {  
  PlatformLocation,  
  Location,  
  LocationStrategy,  
  HashLocationStrategy,  
  PathLocationStrategy,  
  APP_BASE_HREF}  
from 'angular2/platform/common';  

import {BrowserPlatformLocation} from   'angular2/src/platform/browser/location/browser_platform_location';

Another error that's commonly caused by this change is

location.createComponent is not a function

like image 60
Günter Zöchbauer Avatar answered Nov 15 '22 16:11

Günter Zöchbauer