【问题标题】:Meteor infinite redirect instead of render 404Meteor 无限重定向而不是渲染 404
【发布时间】:2015-03-03 12:14:05
【问题描述】:

我的 /lib/router.coffee 中有一个简单的 Iron-router 配置:

Router.configure
  notFoundTemplate: "notFound"

Router.map ->
  @route "app",
    path: "/"
    template: "app"

当输入 / 时,它可以工作,但如果我尝试转到 /abc,那么它会将我重定向到 /#!abc,之后它会将我重定向到 /abc 并无休止地重复(我在地址栏中看到了这些更改浏览器,在浏览器日志中从 / 重定向到 /abc 并返回)。我从来没有看到 404 错误。

有没有人遇到过这样的行为?

我使用 Meteor v1.0.2.1。有我的流星列表:

alethes:lodash           0.7.1
appcache                 1.0.3
coffeescript             1.0.5
ground:localstorage      0.1.7
ground:store             0.1.1
ianhorst:bower           0.0.2
iron:router              1.0.6
meteor-platform          1.2.1
meteorhacks:kadira       2.15.2
peerlibrary:async        0.9.0_3
rzymek:moment            2.8.3_10
rzymek:moment-locale-ru  2.8.4

我也在客户端使用Framework7。

【问题讨论】:

  • 供进一步参考:仅当我启用了appcache 包时才会出现此错误。

标签: web-applications meteor routing iron-router html-framework-7


【解决方案1】:

您拥有的是旧的 Iron-router API,在新的 API 中,我的最后一条路线如下所示:

Router.route('/(.*)', function() {//regex for every route, must be last
    if (this.ready()) {
        document.title = "404";
        this.render('error');
    } else this.render('loading');
})

【讨论】:

  • 我用过这个网址,这就是我需要的。但在我看来,它并不能解释无休止的重定向。
  • 好吧,因为 Iron-router 没有 404 错误,所以我按照你上面看到的方式做了,试试它而不是 Router.configure
【解决方案2】:

尝试在对 Router.configure() 的调用中添加默认布局模板。 notFoundTemplate 旨在填充主布局模板的产量,而不是用作替代 layoutTemplate。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-26
    • 1970-01-01
    • 1970-01-01
    • 2021-10-11
    • 2014-11-16
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    相关资源
    最近更新 更多