meteor - What is wrong with my routing -
meteor - What is wrong with my routing -
i'm trying alter route http://localhost:3000/posts/id http://localhost:3000/posts/title when changing params in router.js '_id' 'title' i'm getting empty page.
i have form working fine:
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'); } });
and router.js:
router.configure({ layouttemplate: 'layout', loadingtemplate: 'loading', waiton: function() { homecoming meteor.subscribe('posts'); } }); router.map(function() { this.route('index', {path: '/'}); this.route('addpost', {path: '/add'}); this.route('postpage', { path: '/posts/:friendlytitle', //empty page friendlytitle, _id working data: function() { console.log(this.params.friendlytitle);return posts.findone(this.params.friendlytitle); //same, _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>
you need specify query criteria.
you have this.
return posts.findone(this.params.friendlytitle);
change this.
return posts.findone({title:this.params.friendlytitle});
if not find take this.params.friendlytitle
_id
, homecoming , empty query
routes more clean*
change route this.
router.route('/posts/title', { name: 'postpage', waiton:function(){ homecoming meteor.subscribe('posts'); //or utilize new subscritionready }, data: function() { console.log(this.params.title) console.log(posts.findone({title:this.params.title});) homecoming posts.findone({title:this.params.title}); } });
using router.map
router.map(function () { this.route('postpage', { path: '/posts/:title', waiton:function(){ homecoming meteor.subscribe('posts'); //or utilize new subscritionready }, data: function(){ homecoming posts.findone({title:this.params.title}); } }); });
use différentes router.map
or router.route
each route.
meteor iron-router
Comments
Post a Comment