【问题标题】:angular routes with rails带导轨的角度路线
【发布时间】:2015-09-01 12:30:13
【问题描述】:

我正在学习 Pro Angular 教程。我有一个关于用角度路线解决铁路路线的问题。

我有以下代码:

$urlRouterProvider.otherwise("/products");

$stateProvider
.state('root', {
  url: "/stores",
  abstract: true,
  template: '<ui-view/>'
})
.state('products', {
  url: "/products",
  templateUrl: "<%= asset_path('store/templates/productList.html') %>",
  controller: "productListCtrl as plCtrl"
})
.state('checkout', {
  url: "/checkout",
  templateUrl: "<%= asset_path('store/templates/checkoutSummary.html') %>"
})

当我转到 localhost:3000 时,我的 url 会自动转到 /products 并显示正确的页面。但是,当我在浏览器上点击重新加载时,我得到一个 rails 错误页面,提示缺少模板产品/索引。

routes.rb

resources :stores, only: :index
get 'stores/*app', to: 'stores#index'

resources :products, only: :index

namespace :api, constraints: {format: :json}, defaults: {format: :json} do
  namespace :v1 do
    resources :products
  end
end

root 'stores#index'

app/views/stores/index.html.slim

base href="/stores"

div ng-app="storeApp"
  ui-view autoscroll="top"

【问题讨论】:

    标签: ruby-on-rails angularjs


    【解决方案1】:

    您的服务器愿意处理路由,但您将任务推迟到客户端。

    因此,您应该始终从服务器渲染基本模板,让客户端自己处理路由。

    routes.rb 末尾添加:

      get  '*a', to: 'stores#index'
    

    其中your_controlleryour_action 匹配您用于root_path 的内容

    【讨论】:

    • 我编辑了帖子,正常回复的用户会收到通知吗?
    • 我不明白你的问题,你试过我的解决方案了吗?
    • 我有以下get 'stores/*app', to: 'stores#index'
    猜你喜欢
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-31
    相关资源
    最近更新 更多