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?
Here is how to RouteConfig for a route parameters
Here is a code from configured app that has routes and route parameters
the plunker for the example
In the full view you can see how the route and routeparams change displaying new content: click here
This might do what you want