是否可以仅将路由器出口作为主要组件? [英] Is it possible to have only the router-outlet as main component?

查看:67
本文介绍了是否可以仅将路由器出口作为主要组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在使用此构造来使路由器插座作为主要应用工作:

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 {
}

是否可以删除虚拟应用程序?我还没有成功.我尝试将 bootstrap 保留为空,或将路由器组件保留在 entry 集合中,但是似乎没有模块配置起作用.

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似乎倾向于要引导一个主要组件.

Angular seems bent on having a main component to bootstrap.

推荐答案

通常,您会在AppModule中的某个地方引导AppComponent,该模板的任何内容+ < router-outlet> .然后,将AppModule初始化为入口点.

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.

没有主要组件作为入口点,我无法想象你怎么能告诉angular应该是应用程序的入口点.

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

我会说这是不可能的.当您在AppModule的引导程序中声明组件时,angular将在index.html中寻找其css选择器.如果未找到->错误.另一方面,如果您未在应用程序模块的bootstrap部分内声明任何内容->错误.此外,如果您尝试在应用程序模块中引导RouterOutet指令

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

未捕获的错误:RouterOutlet不能用作输入组件.

另外, NgModule常见问题解答中的以下引用支持这一点:

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

您可以将子组件嵌入顶部组件的模板中.或者,通过给顶部组件一个< router-outlet> ,使其成为路由主机.定义子路由,然后让路由器将模块组件加载到该插座中.

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.

这篇关于是否可以仅将路由器出口作为主要组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆