[英]Specifying the default template for root route
I have an app for posts
and tags
. 我有一个
posts
和tags
的应用程序。 At the moment they don't have any relations, just in independent state. 目前他们没有任何关系,只是处于独立状态。
I want specify the default template to be postsList
and I had in router.js
: 我想指定默认模板为
postsList
,我在router.js
:
Router.route('/', {name: 'postsList'});
But this screws up the routes for tags
, so I changed routes.js
to look as: 但这会
routes.js
tags
的路由,所以我将routes.js
更改为:
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
waitOn: function () {
return Meteor.subscribe('posts');
return Meteor.subscribe('tags');
}
});
Router.route('/posts', {name: 'postsList'});
Router.route('/posts/:_id', {
name: 'postPage',
waitOn: function () {
return Meteor.subscribe('comments', this.params._id);
},
data: function () {
return Posts.findOne(this.params._id);
}
});
Router.route('/posts/:_id/edit', {
name: 'postEdit',
data: function () {
return Posts.findOne(this.params._id);
}
});
Router.route('/submit', {name: 'postSubmit'});
// Tags Start
Router.route('/tags', {name: 'tagsList'});
Router.route('/tags/submit', {name: 'tagSubmit'});
Router.route('/tags/:_id', {
name: 'tagPage',
data: function () {
return Tags.findOne(this.params._id);
}
});
Router.route('/tags/:_id/edit', {
name: 'tagEdit',
data: function () {
return Tags.findOne(this.params._id);
}
});
// Tags End
// Authentication
var requireLogin = function () {
if (!Meteor.user()) {
if (Meteor.loggingIn()) {
this.render(this.loadingTemplate);
} else {
this.render('accessDenied');
}
} else {
this.next();
}
};
Router.onBeforeAction(requireLogin, {only: ['postSubmit', 'tagSubmit']});
As a result, when I access to root route of the app, it gives me error: 因此,当我访问应用程序的根路由时,它会给我错误:
Oops, looks like there's no route on the client or the server for url: " http://askar-blog.meteor.com/ ."
哎呀,看起来客户端或服务器上没有路由的URL:“ http://askar-blog.meteor.com/ 。”
Any solution? 有解决方案吗
https://github.com/tenzan/blog https://github.com/tenzan/blog
If you're familiar with Rails you can do in routes.rb
: 如果您熟悉Rails,可以在
routes.rb
:
root 'posts#index'
resources :posts
You can just redirect it to go to the appropriate route. 您可以重定向它以转到相应的路线。
Router.route('/', function () {
this.redirect('/posts');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.