Trying new @UIRouterModule...
Hi!
I cloned ui-router into local folder, and built it with npm run build
Then I removed old ui-router-ng2 content in the node_modules folder and copied new content from build_packages\ng2.
Then I changed app.module.ts to:
var homeState = { name: 'home', url: '/home', component: HomeComponent };
var aboutState = { name: 'about', url: '/about', component: AboutComponent };
@UIRouterModule({
imports: [BrowserModule],
declarations: [AppComponent],
states: [homeState, aboutState]
})
export class AppModule {};
and got a error:
Whats wrong?
After I added traceur manually:

I suspect you're using systemjs? I saw this in quickstart-ng2 where SystemJS incorrectly detects ui-router-ng2.js as an ES6 module that needs transpiling. I believe it's parsing something from one of the block comments in the unminified file.
Try one of these things:
- Point systemjs to the
ui-router-ng2.min.jsminified file - Add a
meta:block that says the bundle iscjshttps://github.com/ui-router/quickstart-ng2/blob/rc5compat/systemjs.config.js#L54
Thanks! That worked! But got another error:

@UIRouterModule
({
imports: [
BrowserModule,
],
declarations: [
AppComponent
],
states: [],
providers: [
{provide: LocationStrategy, useClass: HashLocationStrategy},
{provide: UIRouterConfig, useClass: MyUIRouterConfig},
],
bootstrap: [ UIView ]
})
you might need to declare it as an entryComponent
Ho can I do this?
@UIRouterModule
({
imports: [
BrowserModule,
],
declarations: [
AppComponent
],
entryComponents: [
AppComponent
],
states: [],
providers: [
{provide: LocationStrategy, useClass: HashLocationStrategy},
{provide: UIRouterConfig, useClass: MyUIRouterConfig},
],
bootstrap: [ UIView ]
})
Also note: @UIRouterModule is a shortcut for creating a NgModule manually:
https://github.com/angular-ui/ui-router/blob/f6741516a43a605ed7f8f3d1d96517e7e46ef54d/src/ng2/uiRouterNgModule.ts#L50-L66
@christopherthielen What is the official latest release of ui-router-ng2 for npm in order to start using @UIRouterModule? I am updating to RC5. Right now I have "ui-router-ng2": "1.0.0-alpha.5" in my package.json
@christopherthielen Yes! Thats helped! And one more error from second module:

@christopherthielen I fixed it by removing undefined states
uiSref="app.public.user.signup"
uiSref="app.public.user.login"
Now all working perfect!
@kolkov What is the latest release of ui-router to work with angular 2 rc5? Also, where are you importing UIRouterModule from?
@kolkov @christopherthielen nvm I found the quickstart and that is all up to date. Thanks all!
@thegrid22593 No, quickstart is not for UIRouterModule, it's for beta1. UIRouterModule is for future beta2. If you want you can try to build beta2 by yourself as described above.
@thegrid22593 ui-router 1.0.0-beta.2 will be out shortly and contains the UIRouterModule code being discussed, and full NgModule support.
@christopherthielen Great to hear! Thanks!
@christopherthielen What is preferable to use, UIRouterModule or NgModule?
@kolkov UIRouterModule is easier to use (less boilerplate) but it's your own personal choice.
If you use raw NgModule make sure your module provides the states as UIROUTER_STATES_TOKEN with multi: true and also imports the UIRouterRootModule
Thanks! Now we can describe routes for modules separately in the modules themselves? And we no longer need to use this construction in MyUIRouterConfig? INITIAL_STATES.forEach(state => uiRouter.stateRegistry.register(state));
Now we can describe routes for modules separately in the modules themselves? And we no longer need to use this construction in MyUIRouterConfig? INITIAL_STATES.forEach(state => uiRouter.stateRegistry.register(state));
^ correct.
Check out the quickstart rc5 branch: https://github.com/ui-router/quickstart-ng2/tree/rc5compat/src
And what now we do with this function? It is still necessary?
@Injectable()
export class MyUIRouterConfig {
constructor(private injector: Injector) {}
configure(uiRouter: UIRouter) {
// Register each state definition (from app.states.ts) with the StateRegistry
// Define a default behavior, for when the URL matched no routes
uiRouter.urlRouterProvider.otherwise(() => uiRouter.stateService.go("app.public.home", null, null) && null);
}
}
And do we need here injector still?