javascript - 如何仅在当前路线上挂起“活动”课程?
问题描述
我有这样的路线:
this.route('posts', function() {
this.route('index', { path: '/' })
this.route('show', { path: '/:post_path' }, function() {
this.route('people', { path: '/people' })
this.route('files', function() {
this.route('images', { path: '/images' })
this.route('videos', { path: '/videos' })
})
})
}),
我对“活动”类有疑问。
举个例子,这个链接:
http://localhost:4200/posts/1-best-post/files/images
在这种情况下,“活动”类将挂在两个链接上 - onposts.show.files.images
和 on posts.show
。
如何让课堂“活跃”只为posts.show.files.images
?
添加
显然,问题不仅在于“活动”类。但是有了模板。孩子们使用“展示”模板。
您能否解释一下如何正确描述这种嵌套路由?
解决方案
您遇到的问题是因为 ember 对路由器中的每个嵌套函数都有一个隐藏的索引路由。
您的路线文件实际上扩展为如下所示。
this.route('posts', function() {
this.route('index', { path: '/' })
this.route('show', { path: '/:post_path' }, function() {
this.route('index', { path: '/' }) #New
this.route('people', { path: '/people' })
this.route('files', function() {
this.route('index', { path: '/' }) #New
this.route('images', { path: '/images' })
this.route('videos', { path: '/videos' })
})
})
}),
当您定义链接到路径时,我将假设您完全按照它的外观指定它,而不是使用隐藏索引。
# Don't do this
{{#link-to 'posts.show' "1234"}}Posts Show{{/link-to}}
{{#link-to 'posts.show.files.images' "1234"}}Images Show{{/link-to}}
# Do this
{{#link-to 'posts.show.index' "1234"}}Posts Show{{/link-to}}
{{#link-to 'posts.show.files.images' "1234"}}Images Show{{/link-to}}
这个ember-twiddle显示了您遇到的问题的一个示例。顶部显示您遇到的问题。底部显示更正的链接。
同样,您正在使用的 show.hbs 路由将被视为 show 下所有路由的包装器。
如果您在查看文件或图像时不想显示内容,请将逻辑和显示移动到 posts/show/index.js 和 posts/show/index.hbs
推荐阅读
- spring-boot - 使用 Spring Yaml 配置如何为配置文件组合指定配置
- google-calendar-api - 如何检索指定时间段内的所有事件?
- informatica - 如何在不使用 PMCMD 命令的情况下在 Informatica 中的工作流 A 之后触发工作流 B
- android - 为什么 Android Developer Bundle Tool 无法识别我的密钥库中的密钥?
- javascript - Vue 3 改变反应对象
- bundle - 如何在更改自定义数量更改按钮 Magento 2 时更新捆绑产品摘要中的数量?
- discord - 如何发出停止提醒的命令,discord.py?
- php - 从 imagecreatetruecolor() 获取 base64 字符串?
- flutter - Flutter:如何获取http响应头
- python - 试图在 google colab 上创建与我的本地 mysql 数据库的连接