Angular2 routing: nothing appears

I am trying to implement basic routing using 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 debug the problem ^ ^). Here is what I did:

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

Routes:

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

When I access my page, I am correctly redirected to "/ company", so it looks right, but still I can’t see anything. I tried adding the company element to the template of the main component to find out if this component was in order, and when I do this, it displays correctly, so I don't think the problem is with the component.

I checked out a live example from the angular tutorial, and the only difference I see is that they use the Routes decorator instead of RouteConfig. When I do this, WebStorm only detected “Routes” in “angular2 / alt_router”, and it still doesn't work (I have an error: angular does not find my routes) ...

It seems that if the “router socket” is not found / filled, but I have no idea why.

I am using Angular2 beta 17

0
angular routing
source share
1 answer

The difference between the documentation you are reading and the code you are using is the angular version. If you go to the Angular2 website, the Routing and Navigation Link can be highlighted in bold:

 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 old, for which documentation can be found here.

There you can check the sample application to find out what is different from your implementation.

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

+1
source share

All Articles