简体   繁体   English

灰烬无法正确配置路由

[英]Ember not able to configure routes correctly

I have a problem with adding a simple route and am not sure how to debug it. 我在添加简单路由时遇到问题,不确定如何调试它。

I have a route specified as follows 我指定的路线如下

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

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

I also have a form template as follows: 我也有一个表单模板,如下所示:

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

But when I navigate to the url /forms I get an error of page not found. 但是,当我导航到url / forms时,出现找不到页面的错误。

Any ideas where I could start looking to solve this? 有什么想法可以开始解决这个问题吗?

To use non-hash urls like /forms you need to configure Ember's location to use html5 location. 要使用/forms等非哈希网址,您需要将Ember的位置配置为使用html5位置。

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

You will also need to configure your server to render the same index.html that is rendered when you visit /forms . 您还需要配置服务器以呈现访问/forms时呈现的相同index.html。 This will vary as per your server. 这将根据您的服务器而有所不同。

For apache you'll need a mod_rewrite rule. 对于apache,您将需要一个mod_rewrite规则。 For something like rails you need to add a catch all route to use your HomeController 's index page. 对于Rails之类的东西,您需要添加一条catch all路由才能使用HomeController的索引页。 Something like this at end of your routes.rb, 在route.rb的末尾类似这样的内容,

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

This tells the server that anything that doesn't match your previous routes should be rendered with HomeController.index method, or the specific controller that is rendering your application html. 这告诉服务器,任何与您之前的路由不匹配的内容都应使用HomeController.index方法或呈现应用程序html的特定控制器呈现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM