ember.js - Is it possible to make a parent route a 404, but the child route a specific route
问题描述
In my router.js file, I have something that looks like the following
import EmberRouter from '@ember/routing/router';
const Router = EmberRouter.extend({});
Router.map(function () {
this.route('index', { path: '/' });
this.route('foo', function() {
this.route('bar', function() {
this.route('cat');
});
});
this.route('notfound', { path: '/*path' });
});
export default Router;
The problem is that I want the path /foo/bar/cat
to route to the foo.bar.cat
route, but I don't want the paths /foo
or /foo/bar
to route to anything except a 404. In my case, the foo
and bar
routes are essentially useless. I just want the url to have 3 levels for aesthetic purposes.
解决方案
我实际上意识到更有意义的是避免创建foo
和bar
路由并为我想要的路由创建路径。
所以不要在 ember-cli 中这样做:
ember g route foo/bar/cat
我已经做了
ember g route cat
然后我在路由器中设置所需的路径。
Router.map(function () {
this.route('index', { path: '/' });
this.route('cat', { path: '/foo/bar/cat'});
this.route('notfound', { path: '/*path' });
});
这为我提供了正确的路线foo/bar/cat
,但foo
两者foo/bar
都被路由到该notfound
路线。
推荐阅读
- javascript - 没有错误,但 JavaScript 仍然无法工作
- powerbi - DAX 动态日期平均值
- elasticsearch - 查询 elasticSearch 和嵌套对象的问题
- php - 无法通过 MAC (catalina) 上的作曲家安装 laravel 安装程序
- php - Wordpress 批量产品上传 (woocommerce) - 650K
- r - 在闪亮的数据表中编辑多个单元格
- angular - Nested store actions not synchronized
- php - 如何为新包编写 Symfony Flex 配方?
- angular - 为 Angular 应用程序设计
- python - 使用 SimpleITK 执行 3D 共定位和距离测量