3

I have followed all the github issues on HTML5Mode breaking Angular apps in 1.5. I am having the same problem but none of the fixes are working for me.

Im doing the following:

<base href="/">

and

get '/*path', :to => "menus#index"

and

app.config(function($routeProvider, $locationProvider) {
 $locationProvider.html5Mode(true);
 .when("/users/:u_id/restaurants/:r_id/menus/:m_id/edit", { templateUrl: "/assets/menus/edit.html", controller: "MenuSectionCtrl" })
 .when("/users/:u_id/restaurants/:r_id/menus/:m_id/sections/:sec_id/items", { templateUrl:   "/assets/menus/items.html", controller: "MenuItemCtrl" })
 .when("/users/:u_id/restaurants/:r_id/menus/:m_id/sections/:sec_id/items/:i_id/option_sections", { templateUrl: "/assets/menus/option_sections.html", controller: "MenuOptionSectionCtrl" })
 .when("/users/:u_id/restaurants/:r_id/menus/:m_id/sections/:sec_id/items/:i_id/option_sections/:op_sec_id/options", { templateUrl: "/assets/menus/options.html", controller:       "MenuOptionCtrl" })
});

I am lost as to what to do next. I have tried every combination of routes and base[href].

Anybody have any ideas?

Also, I have followed this tutorial too. http://omarriott.com/aux/angularjs-html5-routing-rails/

3 Answers 3

3

Try this link http://start.jcolemorrison.com/angularjs-rails-4-1-and-ui-router-tutorial/

If you have mount only single angularjs application then it is very straight forward. You need to make this entry in routes.rb

get '*path' => 'application#index'

And in your application.controller change the index method as below

def index
  render layout: 'application'
end
Sign up to request clarification or add additional context in comments.

1 Comment

this works and is the simplest solution. Just make sure to put get '*path' => 'application#index' on the bottom of routes.rb. Else all other JSON api endpoints are overwritten.
0

The following link helped me to use rack-rewrite get which seems to work for me. Here is the link. Only the following code in config.ru would allow /api routes to rails:

# config.ru

# This file is used by Rack-based servers to start the application.

use Rack::Rewrite do
  rewrite %r{^(?!.*(api|\.)).*$}, '/index.html'
end

require ::File.expand_path('../config/environment',  __FILE__)
run Rails.application

Comments

-1

I managed to get mine working with:

get '*path', to: redirect('/#/%{path}')

The template I bought was working without hash after the first load but if you refresh the page it does not work. I tried manually adding the hash like /#/page and the above routing does it automatically.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.