【问题标题】:Ember not able to configure routes correctlyEmber 无法正确配置路由
【发布时间】:2013-07-26 15:06:06
【问题描述】:

我在添加简单路由时遇到问题,不知道如何调试它。

我有如下指定的路线

Videos.Router.map(function({
this.resource('videos', {path:'/');
this.route('forms');
})

Videos.FormsRoute = Ember.Route.extend({
renderTemplate: function({
this.render({controller: 'forms'});
}
})

我还有一个表单模板如下:

<script type="text/x-handlebars" data-template-name="forms">

但是当我导航到 url /forms 时,我得到一个找不到页面的错误。

我有什么想法可以开始解决这个问题吗?

【问题讨论】:

  • 找不到页面让我认为您正在使用的服务器正在尝试处理请求并且无法弄清楚要做什么(并且随后不提供页面,客户端确实知道要做什么做),如果你访问 #/forms 怎么办?
  • 是的 #forms 有效!谢谢。我必须做更多的挖掘才能理解这意味着什么。我正在使用 Apache 服务器。

标签: javascript ember.js url-routing


【解决方案1】:

要使用像/forms 这样的非哈希网址,您需要将 Ember 的位置配置为使用 html5 位置。

App.Router.reopen({
  location: 'history'
});

您还需要配置您的服务器以呈现与访问/forms 时呈现的相同的 index.html。这将根据您的服务器而有所不同。

对于 apache,您需要一个 mod_rewrite 规则。对于像rails 这样的东西,您需要添加一条catch all 路线以使用您的HomeController 的索引页面。在你的 routes.rb 末尾有这样的东西,

root :to 'home#index'
match "/*path" => 'home#index'

这告诉服务器任何与您之前的路由不匹配的东西都应该使用HomeController.index 方法或渲染您的应用程序 html 的特定控制器来渲染。

【讨论】:

    猜你喜欢
    • 2020-10-07
    • 2016-12-25
    • 2019-08-17
    • 1970-01-01
    • 2013-02-09
    • 2016-12-28
    • 2016-01-25
    • 2020-07-10
    • 1970-01-01
    相关资源
    最近更新 更多