【问题标题】:Meteor Iron Router - Why does my app always goes to the base url on refresh or url loadMeteor Iron Router - 为什么我的应用程序总是在刷新或 url 加载时转到基本 url
【发布时间】:2014-08-29 22:41:07
【问题描述】:

我有一个使用 Iron 路由器的流星应用程序。每次我刷新浏览器或输入像http://localhost:3000/gigs 这样的网址时,我的应用程序都会刷新回http://localhost:3000 的基本网址

这是我的 router.js 代码

var requireLogin = function() {  
if (!Meteor.user() && !Meteor.loggingIn()) {   
    Router.go('signIn');
    this.stop();  
}
};

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

Router.before(requireLogin, {only: ['tasks', 'gigs']});

Router.map(function() {
this.route('tasks', {
    path: '/', 
    waitOn: function() { return [ Meteor.subscribe('projects'), Meteor.subscribe('tasks') ] },
    layoutTemplate: 'twoColMenuLayout',
    template: 'tasksList',
    yieldTemplates: {l
        'taskDetail': {to: 'rightTemplate'}
    },
    data: {
        moduleName: 'projects'
    }
});

this.route('gigs', {
    path: '/gigs', 
    waitOn: function() { return [ Meteor.subscribe('gigs') ] },
    layoutTemplate: 'twoColMenuLayout',
    template: 'gigsList',
    yieldTemplates: {
        'gigDetail': {to: 'rightTemplate'}
    },
    data: {
        moduleName: 'gigs'
    }
});

this.route('gigSubmit', {
    path: '/gig-submit',
    layoutTemplate: 'oneColMenuLayout',
    template: 'gigSubmit',
    data: {
        pageTitle: 'New Gig'
    }
});

this.route('signIn', { 
    path: '/signIn',
    layoutTemplate: 'blankLayout',
    template: 'signIn'
});
});

奇怪的是,如果我将“tasks”路径更改为“/tasks”而不是“/”,则不会出现此问题,并且可以正常工作。但是,当我这样做时,我会收到一条控制台错误消息,指出未定义“/”。它似乎没有破坏任何东西,但我讨厌控制台中出现错误。

我还尝试将“任务”地图移到底部,以防它首先匹配到这个地图并且总是去那里,但这并没有什么不同。

知道为什么会这样吗?

谢谢!

【问题讨论】:

标签: meteor iron-router


【解决方案1】:

我最近才遇到这种情况。您需要将路线从开始时最深到底部最浅进行排序:

this.route('someDeepRoute', {
    path: '/deep/route', 
});

this.route('gigs', {
    path: '/gigs', 
});

this.route('gigSubmit', {
    path: '/gig-submit',
});

this.route('signIn', { 
    path: '/signIn',
});

this.route('tasks', {
    path: '/', 
});

【讨论】:

  • 我遇到了同样的问题,在底部订购“/”对我不起作用。
猜你喜欢
  • 2014-07-17
  • 1970-01-01
  • 1970-01-01
  • 2016-01-27
  • 2018-06-19
  • 2021-12-06
  • 1970-01-01
  • 2015-08-31
  • 1970-01-01
相关资源
最近更新 更多