javascript - Aurelia 命名为 router-view / viewPorts 不工作
问题描述
我无法使用我在路由配置中指定的视口正确填充布局视图。我有一个路由“styleguide”,它应该使用“sidebar”布局,用“sidebar.html”填充“sidebar”路由器视图,用“content.ts / html”填充“content”路由器视图
应用程序.ts
export class App {
configureRouter(config: RouterConfiguration, router: Router) {
config.map([{
route: "styleguide",
name: "styleguide",
layoutView: "layout/sidebar.html",
viewPorts: {
sidebar: { moduleId: "styleguide/sidebar.html" },
content: { moduleId: "styleguide/index" },
}
}]);
}
}
应用程序.html
<template>
<router-view layout-view="layout/default.html"></router-view>
</template>
layout/default.html(本例中未使用)
<template>
<router-view></router-view>
</template>
布局/sidebar.html
<template>
<router-view name="sidebar"></router-view>
<router-view name="content"></router-view>
</template>
样式指南/sidebar.html
<template>
SIDEBAR!!
</template>
样式指南/index.ts
export class Index { }
样式指南/index.html
<template>
CONTENT
</template>
问题:
- “在 styleguide/sidebar.html 的视图中没有找到路由器视图。” -- 虽然我已经指定了路由器视图名称等。
- 我确实有另一条路线没有指定 a
layoutView
,因此使用默认值。这仅在我将router-view
layout/default.html 中的元素替换为slot
. 我尝试在两种布局中使用插槽,但侧边栏布局给了我同样的错误。
解决方案
你得到的错误是因为你app.html
不支持viewPorts
。只有一个<router-view/>
具有默认名称,因此您的路线配置有 2 个视口,它因上述错误而失败。
根据文档,布局似乎是一种为您的路线实现类似槽的行为的方法,而不是放置<router-view/>
给我的地方,似乎。
推荐阅读
- stripe-payments - Stripe Upcoming Invoice API 在试用期内
- wpf - 在 DataTrigger 绑定中获取选定的 TabControl 名称
- javascript - PHP的“??”有什么等价物 在javascript中操作?
- vim - 为什么标签文件越来越大以及如何避免这个问题
- ffmpeg - `ffmpeg` 的输出是什么意思?
- android - 当点击广告预览时,Facebook 延迟深层链接不起作用
- python-3.x - Python 类:“int”对象在我的类的函数中没有属性
- java - 使用 AWS 转录时主机名不能为空错误
- android - 我想在 Android Studio 的 XML 文件中显示 Native_Ads_view 但它给了我错误
- python - 通过 scapy,在手动编辑数据包时自动更新数据包 TCP 序列和确认号以及 IP 层长度