我正在设置一个身体助手,用于Iron Router用作{{route}}:
Template.body.helpers({
route: function(){
alert(Router.current().route.getName());
}
});
Run Code Online (Sandbox Code Playgroud)
但Router.current().route.getName()返回undefined而不是"/ thirdPage /".
如何使用meteor和Iron-Router从Template.event调用中将官方重定向到另一个路由.我似乎,至少与Dev分支遇到同样的错误
`if (this._isRunning) // 174
throw new Error('Already in a page run'); `
Run Code Online (Sandbox Code Playgroud)
作为一个例子,我有一个按钮,Router.go('/home');如果我运行这个点击调用,我得到'已经在页面运行'错误.其他任何使用路由器路由的方法?
它实际上'this.redirect('/anotherpath')'是导致问题的原因.有没有办法停止当前运行的页面运行并重定向到另一个路由?
我是Meteor的新手,我正在尝试在显示一个段落的页面中设置数据上下文.我需要访问passage_item.js Template.passageItem.rendered中的数据,但此时没有设置上下文.我想我需要{{#with passage}}之类的内容,但one_passage.html中不存在"passage".
以下是一些代码段.谢谢.
router.js
Router.map(function() {
this.route('passagesList', {path: '/'});
this.route('onePassage', {
path: '/passages/:_id',
data: function() { return Passages.findOne(this.params._id); }
});
});
Run Code Online (Sandbox Code Playgroud)
one_passage.html
<template name="onePassage">
{{> passageItem}}
</template>
Run Code Online (Sandbox Code Playgroud)
通路item.html
<template name="passageItem">
<div class="passage">
<div class="one-passage">
<h4><a href= "{{pathFor 'onePassage'}}">{{title}}</a></h4>
<div class="passage-content">
{{content}}
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
passage_item.js
Template.passageItem.helpers({
});
Template.passageItem.rendered = function() {
Meteor.defer(function() {
$('.passage-content').lettering('words');
//I want to be able to access the data object here. I have a list of words that are highlighted
});
};
Run Code Online (Sandbox Code Playgroud) 我正在试验流星和铁:路由器.我git克隆了https://github.com/EventedMind/iron-router.git中的示例.然后我进入了samples/basic,并运行了流星更新和流星.我的流星版本是0.9.3.1
当我导航到网站时,控制台中显示错误,页面为空.错误如下:
Exception from Tracker recompute function: Error: Couldn't find a template named "/" or "". Are you sure you defined it?
at null._render (http://localhost:3000/packages/iron_dynamic-template.js?32038885cb1dad7957291ffebfffcb7f8cd57d20:239:17)
at doRender (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1853:25)
at http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1795:16
at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:2029:12)
at viewAutorun (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1794:18)
at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)
at new Tracker.Computation (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:206:10)
at Object.Tracker.autorun (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:476:11)
at Blaze.View.autorun (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1793:19)
at http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1847:10 debug.js:41
Run Code Online (Sandbox Code Playgroud)
有人可以建议我做错了什么吗?
提前致谢.
我在meteor.js app中创建了一个私有区域; 使用铁路由器,我已经定义了一个控制器,每个私有路由使用:
panelController = RouteController.extend({
waitOn: function() {
Meteor.call('panelAuth', function(error, auth) {
if (!auth) Router.go('/panel/login');
});
}
});
Run Code Online (Sandbox Code Playgroud)
这允许您仅在通过方法'panelAuth'获得服务器端授权时才能输入;
它工作得很好但是如果你尝试在浏览器的地址栏中键入私有路由的url而没有登录(或者没有所需的权限记录)一段时间你可以看到路由呈现,然后你被重定向到登录页面;
我想显示一个loadingTemplate,而'panelAuth'决定你是否可以访问,并避免显示私有路由一段时间
我有一个基本模板:
<template name="ApplicationLayout">
{{> yield}}
</template>
Run Code Online (Sandbox Code Playgroud)
我使用Iron Router将模板路由到它,如下所示:
Router.configure({
layoutTemplate: 'ApplicationLayout',
notFoundTemplate: 'home'
});
Router.route('/', function () {
this.render('home');
});
Run Code Online (Sandbox Code Playgroud)
每当有人到达该网站时,他们将始终显示agegate模板.单击提交按钮后,我想更改为其他页面(主页).
Template.agegate.events({
"click #submit": function (event) {
this.render('home');
}
});
Run Code Online (Sandbox Code Playgroud)
路由实际上工作(我到达所需的页面),但它会抛出一个错误:
Uncaught TypeError: undefined is not a function
我假设这是因为thisin this.render('home')指的是当前模板,而它需要引用父模板(ApplicationLayout模板).但是,我不知道该怎么做,或者这甚至是相关的.
那么,如何才能在Template事件函数中正确路由?
我有这个代码
Template.home.events 'click .buy': (event) ->
event.preventDefault()
???
return
Run Code Online (Sandbox Code Playgroud)
在用户单击按钮(buy)之后,我希望它将转到路由器路径/product.我应该在代码中添加什么?
我刚开始玩Meteor和Iron Router来创建一个简单的网站.网站的导航栏上有一些链接,其中一个被调用random.这个想法是,当用户点击它时,会在页面上显示随机帖子.
现在Iron Router似乎阻止了一个页面重新加载,如果它与当前页面的链接相同.这是一个很棒的功能,除了在我的情况下我需要它重新加载,以便用户可以看到一个新的帖子.
这是相关的代码:
Router.route('/random', function() {
console.log("running this!");
this.layout('SinglePostLayout', {
data: function () { return draw(Posts, {}) }
});
this.render('post');
Run Code Online (Sandbox Code Playgroud)
该draw函数返回集合中的帖子.从完美开始,这很有趣,但这里并不重要.我确认代码只运行了一次console.log.
有没有解决的办法?我想保留除随机链接之外的所有其他链接的无重新加载行为.我已经搜索了一段时间的答案,但找不到任何东西.
谢谢!
我正在使用一个使用ms-seo包的Meteor应用程序.我想知道是否有办法让URL更友好的SEO?
Router.route('/item/:_id', {
name: 'item.detail',
controller: 'ItemsController',
action: 'detail',
where: 'client',
onAfterAction: function() {
var data = this.data();
if (data) {
SEO.set({
title: data.title + ' - ' + data.company + ' (' + data.city + ')',
meta: {
'description': data.descriptionHTML
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
虽然这很完美,但它产生的URL是/item/5RTxofPPn3LwifP24,我想data.title在网址中向上推,所以我可以得到/item/i-am-a-lower-case-dash-replaced-unique-title/
有包裹吗?
我正在为我的应用程序使用IronRouter.最近我想休息一下:
Router.route('/api/hello', { where: 'server' })
.get(function () {
this.response.end('Helo world');
});
Run Code Online (Sandbox Code Playgroud)
我得到了这个例外:
Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions. at AccountsServer.userId (accounts_server.js:80:13) at AccountsServer.user (accounts_common.js:53:23) at Object.Meteor.user (accounts_common.js:230:19) at [object Object]. (lib/routes_permission.js:33:21) at packages/iron_router/lib/router.js:277:1 at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1) at [object Object].hookWithOptions (packages/iron_router/lib/router.js:276:1) at boundNext (packages/iron_middleware-stack/lib/middleware_stack.js:251:1) at runWithEnvironment (packages/meteor/dynamics_nodejs.js:110:1) at packages/meteor/dynamics_nodejs.js:123:1
Run Code Online (Sandbox Code Playgroud)
我在'(lib/routes_permission.js:33:21)中跟踪了这个问题.似乎一切都很好.
// user with no role
Router.onBeforeAction(function() {
var user = Meteor.user(); //This is the line.
if(user && !user.roles) {
this.render('roles');
return; …Run Code Online (Sandbox Code Playgroud)