我有一个ember应用程序,需要以下视图:
/reviews
/users/:id
/users/:id/reviews
我正在与第三个人挣扎。
这是我的router.js
this.route('reviews', function() {
this.route('show', { path: "/:id" });
});
this.route('users', function(){
this.route('show', {path: '/:id'}, function () {
this.route("reviews", function(){});
});
});
此路线的模板位于
templates/users/show/reviews/index.hbs
我的路线在routes/users/show/reviews/index.js
但是当我访问localhost:4200/users/1/reviews
时,它会显示用户个人资料路径(users/:id
- 第二个项目符号点)。就像完全相同一样
如何使用正确的模板和route.js文件使用此路由?
答案 0 :(得分:1)
您的路线应该是:
this.resource('reviews', function() {
this.route('show', { path: '/:id'})
})
之前的意思是您将拥有以下路线:
/reviews
< - 资源审核的默认路由index
/reviews/:id
< - 这是路线show
并且应该有以下文件:
路线 - > app/routes/reviews/show.js
,app/routes/reviews/index.js
控制器 - > app/controllers/reviews/show.js
,app/controllers/reviews/index.js
模板 - > app/templates/reviews/show.hbs
,app/templates/reviews/index.hbs
请注意,如果您没有定义任何以前的文件,则ember默认会生成一个。
对于用户,应遵循与先前定义相同的逻辑。
this.resource('users', function() {
this.resource('user', { path: '/:id' }, function () {
this.route("reviews");
});
});
翻译您将拥有以下路线的用户的先前定义。
/users
&lt; - 资源用户的默认索引</ p>
/users/:id
&lt; - 资源用户的默认索引</ p>
/users/:id/reviews
&lt; - reviews
内users
的路线