I have a single page applications using Angular with the SQL handled by Rails. Most of the routes are handled by Angular's UI-router. However, I have admin routes which I want to be handled by Rails and not be a single page application. What is the best way to have Rails handle the namespaced admin routes? Currently when I navigate to /admin/users, it will redirect me to root.
config.routes.rb
namespace 'admin' do
resources :users
...
end
resources :users
resources :videos
root 'application#index'
get '*path' => 'application#index'
angular_app.js
angular_app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
function($stateProvider, $urlRouterProvider, $locationProvider){
$stateProvider
.state('home', {
url: '/',
templateUrl: 'videos/index.html',
controller: 'VideosController'
})
.state('home.video', {
......
// default fall back route
$urlRouterProvider.otherwise('/');
// enable HTML5 Mode for SEO
$locationProvider.html5Mode(true);
}
]);
How about
namespace 'admin' do
resources :users
...
end
resources :users
resources :videos
get '/', :controller=> 'application',:action=>'index'
This way, You can now access admin routes using admin url helper. Angular would come into picture when '/' is encountered.
If you need to access admin from Angular Page. You can do a Native Javascript Window.href and specify the admin url.