I'm trying to make a simple one component app for testing out Angular2, but I am very stuck on accessing the RouteParams in my app component.
This is what I have so far:
@Component({
selector: 'app',
template: '<h1>ID: {{id}}</h1>',
directives: [ROUTER_DIRECTIVES],
providers: []
})
@RouteConfig([
{ path: '/', component: App }
])
class App {
private id: string
constructor(params: RouteParams) {
this.id = params.get('id')
}
}
bootstrap(App, [
ROUTER_PROVIDERS,
])
So basically what I want to achieve is for the user to go to http://website.com/?id=21 and then for the website to display 21. Do I need to have a separate component for that and then have my AppComponent provide a route to that component or is there any of way of accessing the route parameters in the app component?