Questions tagged [routes]

Questions about mapping URLs to Controllers and Actions.

MVC web application (like Ruby on Rails, ASP.NET MVC, etc) uses routes to map an arbitrary URL to a specific controller/action.

For example

http://example.com/foo/bar/23

Might pass an id 23 to controller foo, action bar.

Unusual URLs could also be mapped

Given controller places and intended action list, we can use routes to allow this URL:

http://example.com/my/places
32975 questions
68
votes
4 answers

:as in rails routes.rb

In config/routes.rb, I tried both: root :to => 'things#index', :as => 'things' and root :to => 'things#index' When I hit http://localhost:3000/, both approaches work, and nothing seems to be different. What is the :as option used for?
ryanprayogo
  • 11,587
  • 11
  • 51
  • 66
68
votes
5 answers

Laravel 5 Resourceful Routes Plus Middleware

Is it possible to add middleware to all or some items of a resourceful route? For example...
kilrizzy
  • 2,895
  • 6
  • 40
  • 63
66
votes
4 answers

Rails/Rspec - testing a redirect in the controller

So I am currently writing a test for a controller in an existing controller that just didn't have one before. What I want to test is a redirect that happens when someone is not allowed to edit something vs someone that is allowed to edit it. the…
legendary_rob
  • 12,792
  • 11
  • 56
  • 102
63
votes
2 answers

Redirect user with router depending on logged in status

I would like to automatically route to a login page if the user is not logged in. app.module.ts import { RouterModule, Routes } from '@angular/router'; import { AppComponent } from './app.component'; import { LoginComponent } from…
Rafael Moura
  • 1,247
  • 2
  • 14
  • 26
62
votes
15 answers

Angular JS Uncaught Error: [$injector:modulerr]

I am having a problem with Angular JS receiving an error : Uncaught Error: [$injector:modulerr]. My JS-file looks angular.module('MyApp', ['ngRoute']); angular.module('MyApp',['ngResource']); function TwitterCtrl($scope,$resource){ } I also…
ig-melnyk
  • 2,769
  • 2
  • 25
  • 35
62
votes
6 answers

In Rails when a resource create action fails and calls render :new, why must the URL change to the resource's index url?

I have a resource called Books. It's listed as a resource properly in my routes file. I have a new action, which gives the new view the standard: @book = Book.new On the model, there are some attributes which are validated by presence, so if a…
rcd
  • 1,348
  • 1
  • 14
  • 27
61
votes
4 answers

Accessing the query string in ASP.Net Web Api?

I'm using the default template generated by Asp.net Web Api. I'm working with the Get() part: // GET api/values public IEnumerable Get() { return new string[] { "value1", "value2" }; } For some reason I thought the only thing you had to…
coding4fun
  • 8,038
  • 13
  • 58
  • 85
60
votes
7 answers

How to store routes in separate files when using Hapi?

All of the Hapi examples (and similar in Express) shows routes are defined in the starting file: var Hapi = require('hapi'); var server = new Hapi.Server(); server.connection({ port: 8000 }); server.route({ method: 'GET', path: '/', handler:…
Centurion
  • 14,106
  • 31
  • 105
  • 197
60
votes
5 answers

Play 2.x: How to make an AJAX request with a common button

So I have successfully gotten AJAX requests to work before but I have always had to use a form, and then at the end of the submit do return false so that it doesn't refresh the page. I have also just recently moved my JavaScript into a separate file…
user1434177
  • 1,947
  • 4
  • 26
  • 40
59
votes
4 answers

Including hash values in ASP.NET MVC URL routes

I need to implement hash value i.e the Url should look like this: /home/index/#create For this have added a route: routes.MapRoute( "Default", // Route name "{controller}/{action}/#{detail}", // URL with parameters new {…
facebook
  • 1,894
  • 3
  • 21
  • 28
59
votes
7 answers

How can I forward localhost port on my container to localhost on my host?

I have a daemon on my host running on some port (i.e. 8008) and my code normally interacts with the daemon by contacting localhost:8008 for instance. I've now containerized my code but not yet the daemon. How can I forward the localhost:8008 on my…
Setheron
  • 3,520
  • 3
  • 34
  • 52
59
votes
5 answers

Recognize routes in rails console Session

Say I have a router helper that I want more info on, like blogs_path, how do I find out the map statements behind that in console. I tried generate and recognize and I got unrecognized method error, even after I did require 'config/routes.rb'
sent-hil
  • 18,635
  • 16
  • 56
  • 74
59
votes
7 answers

How to get list of all routes of a controller in Symfony2?

I have a controller which implements all routes/URL(s). I had the idea to offer a generic index over all help-pages. Is there a way to get all routes defined by a controller (from within a controller) in Symfony2?
Sammy
  • 1,178
  • 1
  • 14
  • 27
58
votes
7 answers

Angular 2 routing redirect to with child routes

I am a newbie in Angular 2. I want to create isolated modules for every part of my app. For example I created the AuthModule with default component - AuthComponent which contain a router-outlet for his child components (SignIn or SignUp). So I want…
Timofey Orischenko
  • 1,148
  • 1
  • 9
  • 12
58
votes
4 answers

Is there something similar to 'rake routes' in django?

In rails, on can show the active routes with rake (http://guides.rubyonrails.org/routing.html): $ rake routes users GET /users {:controller=>"users", :action=>"index"} formatted_users GET /users.:format {:controller=>"users",…
miku
  • 181,842
  • 47
  • 306
  • 310