angular - 角度路由未显示组件内容
问题描述
我在这里创建了我的项目示例:stackblitz
我在我的 Angular 应用程序中实现了路由。作为其中的一部分,我编写了上面的Stackblitz。
在该示例中,有两个组件可用:
- 应用组件
- 登录组件
默认情况下,LoginComponent
只要我们提供 URL,它就应该转到 ,因为/home
它应该呈现AppComponent
.
应用程序路由.module.ts
const appRoutes:Routes=[
{ path: '', component: LoginComponent },
{ path: 'home', component: AppComponent },
{ path: '**', redirectTo: '/not-found', pathMatch: 'full' }
]
App.component.html
<div class="container">
<h2> Hello App component</h2>
</div>
<router-outlet></router-outlet>
但问题是默认情况下它在同一页面中显示appcomponent
和内容。LoginComponet
任何人都可以帮忙吗?
谢谢
解决方案
好的,根据我们的评论,我遇到了问题。如果在除. <router-outlet></router-outlet>
_ <app-root></app-root>
_login.component.html
component.html
app.component.html
<router-outlet></router-outlet>
在你的设计中,你必须在整个应用程序中只有一个。在app.component.html
你必须只是有<router-outlet></router-outlet>
,没有别的。如果您有一些其他内容要app.component.html
提取它们并放入具有新路由的新组件中。应该没问题。
推荐阅读
- python - 按白天和黑夜分开值
- react-native - 反应将打开我的应用程序的本机后台任务。有可能吗?
- c# - 如何在对象列表上执行分组
- bazel - Bazel 函数:git_repository 与 new_git_repository?
- azure-data-factory - Azure 数据工厂 - 将未知数量的文件复制到相应的表中
- google-sheets - 需要根据 2 个标准获得价值,或
- php - cakePHP 使用 I18 Time addMinutes 函数更新每个相关变量,而不仅仅是当前实例
- node.js - mongodb句柄嵌入sous文档更新
- r - R:如果在相应的行中没有找到某个数字,则打印 ID 值
- r - 是否可以检索通过 Rmarkdown 中的闪亮参数选择的文件的原始文件位置?