[英]Angular routing not working correctly
So I am attempting to try out Angular routing in my Ruby on Rails application. 因此,我尝试在Ruby on Rails应用程序中尝试Angular路由。
The problem is that, when I land on a route, let's say '/'
, and I have a angular routing that say's that when I land on it, it should load a template in my desired directory, then my Rails server will throw this error: 问题是,当我着陆时,假设为'/'
,并且有一个角度路由,即当我着陆时,它应该将模板加载到所需的目录中,然后我的Rails服务器会抛出该模板错误:
Started GET "/templates/index.html.erb" for 127.0.0.1 at 2014-12-02 18:03:39 +0200
ActionController::RoutingError (No route matches [GET] "/templates/index.html.erb"):
So basically it seems that it does not attempt to load my file from the folder but instead it tries to put the path that I told the angular route to the URL, and then make a request? 因此,基本上,似乎它没有尝试从文件夹加载我的文件,而是尝试将我告诉角度路由的路径放入URL,然后发出请求?
Because if I replace the templateUrl:
with /users
, which is an actual route in my app that responds with html, then It will effectily route to it. 因为如果我用/users
替换templateUrl:
:,这是我的应用程序中用html响应的实际路由,那么它将有效地路由到它。 But that is not the behaviour I want. 但这不是我想要的行为。
I want Angular to replace the html template in my ng-view with the template specified when I enter the called route. 我希望Angular将ng-view中的html模板替换为输入调用路由时指定的模板。
Here is my code for angular routing: 这是我的角度路由代码:
App = angular.module("App", ['ngRoute', 'growlNotifications'])
App.config ($httpProvider) ->
authToken = $("meta[name=\"csrf-token\"]").attr("content")
$httpProvider.defaults.headers.common["X-CSRF-TOKEN"] = authToken
App.config ($routeProvider, $locationProvider) ->
$locationProvider.html5Mode true
$routeProvider
.when '/',
templateUrl: 'templates/index.html.erb',
controller: 'VisitorsCtrl'
.when '/users',
templateUrl: '../../views/users/index.html.erb',
controller: 'UsersCtrl'
.otherwise redirectTo: "/"
Also, in my application.html.erb
I have set the base href
to '/'
另外,在我的application.html.erb
我将base href
设置为'/'
My template are located currently as so: app/assets/javascripts/angular/templates
and my routing is defined in the angular
folder 我的模板的当前位置如下: app/assets/javascripts/angular/templates
,我的路由在angular
文件夹中定义
What could be the problem here? 这可能是什么问题?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.