0

I'm trying to implement basic routing with Angular2 but without success :-D Actually, I don't even have an error, I just get nothing on the page (which does not help me to debug the issue ^^). Here's what I did:

  • Bootstrap "ROUTER_PROVIDERS" from 'angular/router'
  • Define the routes in the main component (see below).
  • Add a "router-outlet" element in the template of the main component.
  • The main component implements "ngOnInit" and uses the router to redirect the user to the route named "Company".

The routes:

@RouteConfig([
    { path: '/company', component: CompanyComponent, name: 'Company' },
    { path: '/missions', component: MissionComponent, name: 'Mission' }
])

When I access my page, I'm correctly redirected to "/company", so it looks like the routes are correctly defined, but still, I don't see anything. I tried to add the "company" element in the main component template to see if this component was OK, and when I do that, it appears correctly, so I don't think that's a component related issue.

I checked the live example from angular tutorial and the only difference I see is that they use "Routes" decorator instead of "RouteConfig". When I do that, WebStorm only found "Routes" in "angular2/alt_router" and it does not work anyway (I have an error saying Angular does not find my routes)...

It just looks like if the "router-outlet" is not found/filled up, but I have no idea why.

I'm using angular2 beta 17

1
  • kind of difficult to say anything without AppComponent, CompanyComponent and MissionComponent code Commented May 16, 2016 at 21:46

1 Answer 1

1

The difference you have between the documentation you are reading and the code you are using is the angular version. If you go to the site of Angular2 Routing & Navigation link you can see in bold it states:

This chapter is a work in progress.

It describes the release candidate Component Router which replaces the beta router.

The version you are using is the old one, for which the documentation can be found here

There you can check the sample app to see what's different from your implementation.

However I would suggest you upgrade to the RC version of angular2 instead of using the beta version.

Sign up to request clarification or add additional context in comments.

3 Comments

Just did that, now... nothing works anymore ^^ But I just took a look at the quick start en it looks like a lot of thing has changed in the systemjs configuration and right now, my app can't seem to load "core.js", "router.js",... So I guess I have to update my configuration. I'll come back here when I can get something to work. Thanks
Ah aaaah. That was it. After switching to rc1, I finally got it to work. Thanks ;-)
You are welcome. I'm learning and trying to work with Angular 2 since alpha :) Lot was constantly changing, but at least know that we are getting to the final release things are settling down :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.