admin管理员组文章数量:1178545
In Meteor I'm using Backbone in order to provide routing for the different pages in my app. I currently have a profile and an administration page. When I go to the profile page it shows up just as it should, however when I go to administration Meteor falls back to the main page.
As a side-note, if anyone has a better pattern or best-practice for pages in Meteor feel free to share as this is quite cumbersome.
I use the following template to decide what page to show:
<template name="root">
{{> navbar}}
{{#if pageIs "profile"}}
{{> profile}}
{{else}}{{#if pageIs "administration"}}
{{> administration}}
{{else}}
{{> main_page}}
{{/if}}
{{/if}}
</template>
The pageIs method is as follows:
Template.root.pageIs = function(page){
console.log(Session.get('page'));
return page === Session.get('page');
}
And the following code in my Backbone router:
var ProtonRouter = Backbone.Router.extend({
routes: {
"profile": "profile",
"admin": "administration",
"administration":"administration"
},
profile: function () {
Session.set('page','profile');
},
administration: function (){
Session.set('page', 'administraion');
},
mainPage: function(){
Session.set('page',null);
}
});
The log statement in the pageIs method will log undefined a couple of times and then log the correct page, even on administration, however Meteor doesn't seem to reload the selected page anyway and the template still hits the last else-statement.
In Meteor I'm using Backbone in order to provide routing for the different pages in my app. I currently have a profile and an administration page. When I go to the profile page it shows up just as it should, however when I go to administration Meteor falls back to the main page.
As a side-note, if anyone has a better pattern or best-practice for pages in Meteor feel free to share as this is quite cumbersome.
I use the following template to decide what page to show:
<template name="root">
{{> navbar}}
{{#if pageIs "profile"}}
{{> profile}}
{{else}}{{#if pageIs "administration"}}
{{> administration}}
{{else}}
{{> main_page}}
{{/if}}
{{/if}}
</template>
The pageIs method is as follows:
Template.root.pageIs = function(page){
console.log(Session.get('page'));
return page === Session.get('page');
}
And the following code in my Backbone router:
var ProtonRouter = Backbone.Router.extend({
routes: {
"profile": "profile",
"admin": "administration",
"administration":"administration"
},
profile: function () {
Session.set('page','profile');
},
administration: function (){
Session.set('page', 'administraion');
},
mainPage: function(){
Session.set('page',null);
}
});
The log statement in the pageIs method will log undefined a couple of times and then log the correct page, even on administration, however Meteor doesn't seem to reload the selected page anyway and the template still hits the last else-statement.
Share Improve this question asked Nov 29, 2012 at 8:56 RichardRichard 3,2972 gold badges32 silver badges54 bronze badges3 Answers
Reset to default 25UPDATE: Iron router is being deprecated in favor of Flow Router. There are strong indications that Flow Router will be supported as part of core Meteor in the future.
https://github.com/meteorhacks/flow-router
OUTDATED: The previously commonly used router was Iron Router:
https://github.com/EventedMind/iron-router
At its release, Iron Router combined the efforts of the authors of the two most widely used meteor routers (meteor-router and mini-pages), and was the de facto offcial router for Meteor prior to Flow Router.
Lot of people use this route system:
https://github.com/tmeasday/meteor-router
It's really easy to use and made for Meteor.
In the early days of Meteor the recommendation was to use Backbone for routing.
The router Andrew pointed out in his post, has become the most popular choice: https://github.com/iron-meteor/iron-router
A more minimalistic solution is flow router: https://github.com/meteorhacks/flow-router
To make an informed decsion which one to use, you can read about the differences of both routers.
本文标签: javascriptRouting in MeteorStack Overflow
版权声明:本文标题:javascript - Routing in Meteor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738108903a2064463.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论