Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular + Rails + Routing?

How does one handle the differences in routing between client side routing in Angular and server side routing in Rails? Do you have to choose one or the other? For example if I have a Rails application backend and an Angular application frontend, would I have to use the location service to determine which requests to make to my Rails server if I'm using Angular routing? And if I am using Rails routing would I be required to manually keep track of all my controllers interactions and dependencies on the main module? Are there benefits or drawbacks from using one or the other, is it even possible to combine the two?

like image 622
Ben Nelson Avatar asked Feb 20 '14 19:02

Ben Nelson


People also ask

How does routing work in Rails?

Rails routing is a two-way piece of machinery – rather as if you could turn trees into paper, and then turn paper back into trees. Specifically, it both connects incoming HTTP requests to the code in your application's controllers, and helps you generate URLs without having to hard-code them as strings.

What is Angular routing used for?

Angular Routinglink As users perform application tasks, they need to move between the different views that you have defined. To handle the navigation from one view to the next, you use the Angular Router . The Router enables navigation by interpreting a browser URL as an instruction to change the view.

What is Angular routing in Angular?

Routing in Angular allows the users to create a single-page application with multiple views and allows navigation between them. Users can switch between these views without losing the application state and properties.

What are routing types in Angular?

Angular Router supports multiple outlets in the same application. A component has one associated primary route and can have auxiliary routes. Auxiliary routes enable developers to navigate multiple routes at the same time.


1 Answers

Actually, you have to do routing on both side. On your angular app side you will need to manage the routing of your pages and on the rails side you need to manage the routing for requests sent to the server. For example, on the app i'm switch page and looking at different pages, angular can do that (altough you could ask your rails server to render the html pages). Let's say i am creating an user, you will need to route the request on the server side to access the controller to create a user model.

like image 147
ogm Avatar answered Sep 27 '22 20:09

ogm