标签: iron-router

如何在Iron Router blaze集成上正确替换this.stop()with pause()

当我将Iron Router升级到blaze集成分支时,我开始收到此警告:

"You called this.stop() inside a hook or your action function but you should use pause() now instead" 
Run Code Online (Sandbox Code Playgroud)

Chrome控制台 - > iron-router.js:2104 - > client/route_controller.js:193 from package

代码在客户端:

Router.before(mustBeSignedIn, {except: ['userSignin', 'userSignup', 'home']});

var mustBeSignedIn = function () {
    if (!Meteor.user()) {
        // render the home template 
        this.redirect('home');
        // stop the rest of the before hooks and the action function 
        this.stop();
        return false;
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)

我试着更换this.stop()同:pause(),Router.pause()this.pause(),但仍然无法正常工作.另外我还没有在铁路由器包上找到暂停功能.

如何正确更换this.stop()用 …

meteor iron-router

8
推荐指数
2
解决办法
2266
查看次数

用户刚刚登录或刚刚注销后如何重定向

似乎Deps.autorun是要走的路,但是Router.go似乎在Deps.autorun中不起作用.

meteor iron-router

8
推荐指数
2
解决办法
7359
查看次数

完全混淆了流星铁路由器中的this.next()

我升级到Meteor 1.0,安装了最新的铁路由器包,尝试运行我的应用程序并在我的控制台日志中得到了这个好警告:

路线调度从未呈现.你忘了在onBeforeAction中调用this.next()吗?

所以我尝试根据新版本修改我的路线.

this.route('gamePage', {
        path: '/game/:slug/',
        onBeforeAction: [function() {
            this.subscribe('singlePlayer', this.params.slug).wait();
            var singlePlayer = this.data();
            if (singlePlayer) {
                if (singlePlayer.upgrade) {
                    this.subscribe('upgrades', this.params.slug).wait();
                    this.next();
                }
                this.next();
            }
            this.next();
        }],
        data: function() {
            return Games.findOne({slug: this.params.slug});
        },
        waitOn: function() { return [Meteor.subscribe('singleGame', this.params.slug)]}
    });
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?任何帮助将不胜感激.

javascript meteor iron-router

8
推荐指数
1
解决办法
4599
查看次数

Meteor加载脚本,特定于页面的CSS

我目前遇到的问题是,我希望能够只执行特定的脚本和CSS文件,因为如果在错误的页面上执行,它会在浏览器控制台中产生错误.

我正在为Meteor使用"Iron router",只使用基本代码才能使其正常工作.现在,有没有办法让我发送脚本作为参数,所以它只加载我想要加载页面的那些?

javascript css meteor iron-router

7
推荐指数
1
解决办法
1472
查看次数

使用Iron Router,"路由器未定义"

我已经添加了铁路由器到我的应用程序来处理主页,关于页面和应用程序的主页面之间的路由,这是一张地图

在添加了带有陨石的铁路由器之后,我写了一个router.js文件并将其放在我的/ client文件夹中,但是我收到的错误是"未捕获的ReferenceError:未定义路由器"

我用chrome devtools检查了错误,它指向我在下面添加的router.js开头的"Router.configure(..."

Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading'
});

Router.map( function () {
//the about route
this.route('about', {
    path: '/about',
    template: 'about',
    action: function () {
        console.log('now routing the about template');
    }
});

this.route('home', {
    path: '/',
    template: 'home',
    action: function () {
        console.log('now routing the home template');
    }
});

//the map route
this.route('map', {
    path: '/map',
    template: 'map',
    action: function () {
        console.log('now routing the map template');
    }

});
});
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么我收到路由器未定义的错误?

meteor iron-router

7
推荐指数
1
解决办法
6808
查看次数

流星和铁路由器:当id不存在时提高404

我正在使用Iron Router作为我的网址,我有这条路线:

this.route('regionEdit', {
  path: '/region/:_id',
  waitOn: function() {
    return Meteor.subscribe('region', this.params._id);
  },
  data: function() {
    return Regions.findOne({
      _id: this.params._id
    });
  }
});
Run Code Online (Sandbox Code Playgroud)

当我使用这条路径时,这很好用 http://example.com/region/xgok3Etc5mfhtmD7j

哪里xgok3Etc5mfhtmD7j_id区域的.但是,当我访问时http://example.com/region/whatever,页面正常呈现,但没有数据.

如何为此引发404错误?

meteor iron-router

7
推荐指数
2
解决办法
3261
查看次数

用流星铁路由器中止导航

我在Meteor应用程序中有一个(客户端)路由器,并使用{{pathFor}}帮助程序进行链接.

我在用户更改表单字段时设置了一个dirty标志Session,并且我想触发警告并允许用户在设置标志时停止从页面导航,基本上就像onunload处理程序一样.

我试过这样做:

Router.onBeforeAction(function(pause) {
    var self = this;

    if (!this.ready()) {
        return;
    }

    if(Session.get('dirty')) {
        if(!confirm("Are you sure you want to navigate away?")) {
            pause();
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

然而,当我得到提示时,我仍然被引导离开.也就是说,pause()似乎没有停止后续的路由器操作,无论它是什么.

我究竟做错了什么?

meteor iron-router

7
推荐指数
2
解决办法
1015
查看次数

铁路由器路由与Meteor之间的动画页面转换

目前,我发现在路由之间设置动画的唯一解决方案是淡出当前页面onBeforeAction并淡入新页面onAfterAction.但这只是跛脚.

我想尝试执行一些非常流畅的过渡.

我认为这需要在页面上同时呈现多个页面,但这似乎非常耗费资源,甚至根本不使用铁路由器.

我有什么想法可以实现这个?

meteor iron-router

7
推荐指数
1
解决办法
3235
查看次数

如何重新加载当前的铁路由器路由?

如果我现在在/foo,Router.go '/foo'什么都不做.我想要/foo动作钩子和渲染重做.我知道我可以创建一个依赖项,在一个动作钩子中提及它,并在我需要重新加载时使它失效,我只是希望有一个Router.*我可以使用的api,因为那样会更清晰.

meteor iron-router

7
推荐指数
1
解决办法
2866
查看次数

Meteor.user()在页面重新加载后返回undefined

我想检查用户是否通过我的路线中的onBeforeAction内的Meteor.user()登录.问题是,在页面重新加载之后,Meteor.user()在加载之前会在一瞬间返回undefined.

这里我的路线配置:

Router.map(function() {
    this.route('list', {
        path: '/list',
        template: 'list',
        onBeforeAction: function(){
            console.log('onBeforeAction');
            if(!Meteor.user()){
                 Router.go('/login');
            }
            this.next();
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

我搜索了很多,并使用"waitOn"和"返回Meteor.user();"进行了解决方法.似乎在我的情况下不起作用.同样有趣...本地它工作得非常好,所以我可以重新加载页面并仍然保持在"列表"视图中,但是模块上部署的应用程序如上所述并重定向到登录页面.

有任何想法吗?提前致谢.

meteor iron-router

7
推荐指数
1
解决办法
1672
查看次数

标签 统计

iron-router ×10

meteor ×10

javascript ×2

css ×1