Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在Rails/Angularjs html5模式下删除重定向_Ruby On Rails_Angularjs - Fatal编程技术网

Ruby on rails 如何在Rails/Angularjs html5模式下删除重定向

Ruby on rails 如何在Rails/Angularjs html5模式下删除重定向,ruby-on-rails,angularjs,Ruby On Rails,Angularjs,在rails中使用HTML5模式时,如何避免每次用户刷新angularjs页面时对性能的影响?我使用的是AngularJSHTML5模式RubyonRails路由重定向。如果我访问http://localhost:3000/usersurl立即变为http://localhost:3000/?goto=users然后重定向到http://localhost:3000/users。在使用html5模式时,如何避免这种性质的重定向 铁路线路 结束 角路线 以上内容来自此博客:只需使用此rails路线

在rails中使用HTML5模式时,如何避免每次用户刷新angularjs页面时对性能的影响?我使用的是AngularJSHTML5模式RubyonRails路由重定向。如果我访问
http://localhost:3000/users
url立即变为
http://localhost:3000/?goto=users
然后重定向到
http://localhost:3000/users
。在使用html5模式时,如何避免这种性质的重定向

铁路线路 结束

角路线
以上内容来自此博客:

只需使用此rails路线即可:

  # Route all valid requests to AngularJS
  root to: 'application#home'
  get "*path" => "application#home"
和rails action_控制器:

  # We'll just use this as a launch point for our App
  def home
    # Render just the layout since this application is Angular driven
    # our layout/application has all the angular logic and our controllers
    # have no views for themselves. We just need a place to launch from
    # and this happens to be it. So we have no view (thus :nothing => true)
    # but we still want the layout (since it has the App bootstrap code)
    render :layout => 'application', :nothing => true
  end

现在不需要处理来自angularjs路由器的重定向。只需简单地转到页面即可。

这里有另一种剥这只猫皮的方法:

#文件
gem“机架重写”
#config.ru
#基于机架的服务器使用此文件启动应用程序。
使用Rack::重写do
重写%r{^(?。*(api |\).$},'/index.html'
结束
require::File.expand_path(“../config/environment”,_文件)
运行Rails.application
资料来源:

  # Route all valid requests to AngularJS
  root to: 'application#home'
  get "*path" => "application#home"
  # We'll just use this as a launch point for our App
  def home
    # Render just the layout since this application is Angular driven
    # our layout/application has all the angular logic and our controllers
    # have no views for themselves. We just need a place to launch from
    # and this happens to be it. So we have no view (thus :nothing => true)
    # but we still want the layout (since it has the App bootstrap code)
    render :layout => 'application', :nothing => true
  end