1
votes

I have an AppComponent that holds main navigation bar and router outlet for the rest of the application. Now, by convention, this is my starting point of Angular2 application.

I also have routes component which will hold my routes(currently is empty).

What happens is the following: when I start the application, I get an error in console:

EXCEPTION: Error: Uncaught (in promise): Error: Cannot match any routes: ''

I am aware of why is this happening. My question is: is it possible to have an AppComponent as your default route? Or do I have to have a separate component that will hold the initial UI and register it in routes component with an empty(default) path and then inject it into AppComponent?

1
Can you show your code for this? - Ha Hoang
There is no code needed, this was more of a general question. @micronyks provided an answer down below in the comment: "router-outlet must have one view in it" - Nodios

1 Answers

1
votes

Note : You have to make sure that default route is set when router-outlet is used.


is it possible to have an AppComponent as your default route

what do you mean by default route? You can have AppComponent as your bootstrap component which comes to the screen first. AppComponent may contain router-outlet for other component.

According to your routes, you can inject default route/view/component into router-outlet.

So when you run app, you'll have AppComponent with (let's say) HomeComponent.

So Answer is YES

Look at this plunker. It has AppComponent, it loads HomeComponent(Feature Component) as default. Moreover, AppComponent has two router links.

https://plnkr.co/edit/aw3BZxUwsjnkVqhZI4GW?p=preview