Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have only the router-outlet as main component?

Tags:

angular

Currently I'm using this construction to get my router-outlet working as the main app:

@Component({
    selector: 'my-dummy-app',
    template: '<router-outlet></router-outlet>'
})

export class MyDummyApp {
}

Is it possible to cut out the dummy app? I've not had any success. I've tried leaving bootstrap empty, or keep my router-components in the entry collection, but no module config seems to work.

Angular seems bent on having a main component to bootstrap.

like image 717
Benny Bottema Avatar asked Nov 30 '25 12:11

Benny Bottema


1 Answers

Normally you would bootstrap the AppComponent, whos template is anything + <router-outlet> in some place, in the AppModule. Afterwards you would initialize the AppModule as entry point.

Without a main component as entry point I cant imagine how could you tell angular what should be the entry point of the application.

I would say its not possible. When you declare a component in bootstrap in the AppModule, angular will look for its css selector in index.html. If not found -> error. In the other hand, if you dont declare anything inside of the bootstrap section in your app module -> error. Furthermore, if you try to bootstrap the RouterOutet directive in your app module

Uncaught Error: RouterOutlet cannot be used as an entry component.

Also the following quote from the NgModule FAQ seems to support this:

You can embed the child components in the top component's template. Alternatively, make the top component a routing host by giving it a <router-outlet>. Define child routes and let the router load module components into that outlet.

like image 99
Jota.Toledo Avatar answered Dec 03 '25 01:12

Jota.Toledo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!