angular - 一个具有多个组件的路由
问题描述
问题: 如何为一条路线定义 2 个组件?
我的网站如下图所示。白盒子是静态的,永远不会改变,左边和右边的盒子总是根据我去的路线而变化。
http://myapp.com/route
这应该显示 route-left.component 和 route-right.component。然而:
http://myapp.com/another
应该显示 another-left.component 和 another-right.component。
我一直在努力寻找解决方案,但没有运气。我知道路由器选择了第一条路由并且只得到了那个组件。不知道如何做 2 个组件。我目前的代码是:
路由器模块.ts
import { RouteLeftComponent } from '...';
import { RouteRightComponent } from '...';
import { AnotherLeftComponent } from '...';
import { AnotherRightComponent } from '...';
// import Your Canvas View
const appRoutes: Routes = [
{path: '', redirectTo: '/router', pathMatch: 'full'},
{path: 'router', component: RouteRightComponent},
{path: 'router', component: RouteLeftComponent, outlet="sidebar"},
{path: 'another', component: AnotherRightComponent},
{path: 'another', component: AnotherLeftComponent, outlet="sidebar"},
]
@NgModule({
declarations: [
RouteRightComponent,
RouteLeftComponent,
AnotherRightComponent,
AnotherLeftComponent
],
exports: [ RouterModule ],
imports: [ RouterModule.forRoot(appRoutes)],
})
export class RoutingComponent {}
html文件只有:
<router-outlet name="sidebar"></router-outlet>
...
<router-outlet></router-outlet>
欢呼帮助
解决方案
推荐阅读
- c# - 列表
.RemoveAll() 效率/编译器优化 - tensorflow - 无法使用 tensorflow 和 gpu 运行光线调谐
- python - 从 Python 中启动命令提示符应用程序/脚本,捕获输出并发送输入
- r - 以 6 开头的数字日期的起源是什么?
- java - 在 IBM JVM 1.8 上使用 mock-maker-inline Mockito 插件
- c# - 使用 oauth2.0 成功生成访问令牌后,将文件/文件夹上传到 Webapplication 中的 onedrive/sharepoint
- java - Jersey POST 方法参数为空
- javascript - TypeError:Recaptcha 不是构造函数
- authentication - Using ambassador authservice to only require basic auth on some routes/urls (or services)
- antlr4 - how to use sequence for tokenazation but not returned as par of result