0
我试图将我的路由http://localhost:3000/posts/id更改为http://localhost:3000/posts/title,但是在将router.js中的params从'_id'更改为'title'时,我得到空白页面。我的路由有什么问题
我有一种形式,做工精细:
Template.addpost.events({
'submit form': function(e) {
e.preventDefault();
var query = {
title: $(e.target).find('[name=title]').val(),
text: $(e.target).find('[name=text]').val() ,
image: $(e.target).find('[name=image]').val(),
intro: $(e.target).find('[name=intro]').val(),
friendlyTitle: slugify($(e.target).find('[name=title]').val()),
author: Meteor.user().profile.name
};
query._id = Posts.insert(query);
Router.go('index');
}
});
而且我router.js:
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
waitOn: function() { return Meteor.subscribe('posts'); }
});
Router.map(function() {
this.route('index', {path: '/'});
this.route('addpost', {path: '/add'});
this.route('postPage', {
path: '/posts/:friendlyTitle', //empty page with friendlyTitle, but with _id working good
data: function() { console.log(this.params.friendlyTitle);return Posts.findOne(this.params.friendlyTitle); //same, with _id working good}
});
});
Router.onBeforeAction('loading');
postPage.html:
<template name="postPage">
<div class="container main">
<div class="col-md-12"><h1>{{title}}</h1></div>
<div class="col-md-12">
{{{text}}}
</div>
</div>
</template>
要清楚,您需要为posts/title和posts /:id,correect创建单独的路线? –
我不认为bartezr希望'posts /:_ id'路线了 – Ethaan