Skip to content

Instantly share code, notes, and snippets.

@joeherold
Last active November 23, 2015 12:52
Show Gist options
  • Save joeherold/f4b6335ff02332e267c9 to your computer and use it in GitHub Desktop.
Save joeherold/f4b6335ff02332e267c9 to your computer and use it in GitHub Desktop.
import { Http, HTTP_PROVIDERS } from 'angular2/http';
import { ROUTER_DIRECTIVES, RouteConfig, RouterOutlet, RouterLink, AsyncRoute, Router, RouteRegistry } from 'angular2/router';
import { ROUTER_PRIMARY_COMPONENT, APP_BASE_HREF, ROUTER_PROVIDERS as NG2_ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy,PathLocationStrategy } from 'angular2/router';
// import your components, you want to use for routes
import {MyPluginComponent, MyAnotherPluginComponent} from './myComponents/components';
@Component({
//your definitions here
})
@View({
//your definitions here !dont forteg <router-outlet></router-outlet>
directives: [CORE_DIRECTIVES, RouterOutlet]
template:`
<div class="routerOutlets">
<router-outlet></router-outlet>
</div
`
})
@RouteConfig([
{path:"/my-plugin", compontent:MyPluginComponent, as: "MyPlugin"} ,
{path:"/another-plugin", compontent:MyAnotherPluginComponent, as: "AnotherPlugin"} ,
])
class App {
constructor(){}
}
/**
* provide a custom ROUTER_PROVIDERS with customized providers
* @type {any[]|Provider[]}
*/
const ROUTER_PROVIDERS:Array<any> = [
NG2_ROUTER_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {
useValue: App
}),
provide(LocationStrategy, { //here you define wheter you use example.org/#/path or example.org/path
useClass: HashLocationStrategy //with #/
//useClass: PathLocationStrategy // without #/
}),
provide(APP_BASE_HREF, { //this is very important and mostly forgetten and causing an error, when not set
useValue: '/'
})
];
/**
* bootstrap the application
*/
bootstrap(App, [HTTP_PROVIDERS, ROUTER_PROVIDERS]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment