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
175
votes
4 answers

Laravel - Route::resource vs Route::controller

I read the docs on the Laravel website, Stack Overflow, and Google but still don't understand the difference between Route::resource and Route::controller. One of the answers said Route::resource was for crud. However, with Route::controller we can…
Sonique
  • 6,670
  • 6
  • 41
  • 60
173
votes
18 answers

Next.js Redirect from / to another page

I'm new in Next.js and I'm wondering how to redirect from start page ( / ) to /hello-nextjs for example. Once user loads a page and after that determine if path === / redirect to /hello-nextjs In react-router we do something like:
Arthur
  • 3,056
  • 7
  • 31
  • 61
163
votes
4 answers

Difference between [routerLink] and routerLink

What is the difference between [routerLink] and routerLink ? How should you use each one?
Eslam Tahoon
  • 2,205
  • 4
  • 15
  • 21
156
votes
21 answers

Angular2 Routing with Hashtag to page anchor

I wish to add some links on my Angular2 page, that when click, will jump to specific positions within that page, like what normal hashtags do. So the links would be something like /users/123#userInfo /users/123#userPhoto /users/123#userLikes etc. I…
Stone
  • 1,811
  • 2
  • 14
  • 14
155
votes
8 answers

How can I have lowercase routes in ASP.NET MVC?

How can I have lowercase, plus underscore if possible, routes in ASP.NET MVC? So that I would have /dinners/details/2 call DinnersController.Details(2) and, if possible, /dinners/more_details/2 call DinnersController.MoreDetails(2)? All this while…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
152
votes
15 answers

How do I remove the Devise route to sign up?

I'm using Devise in a Rails 3 app, but in this case, a user must be created by an existing user, who determines what permissions he/she will have. Because of this, I want: To remove the route for users to sign up. To still allow users to edit their…
Nathan Long
  • 122,748
  • 97
  • 336
  • 451
151
votes
7 answers

API Versioning for Rails Routes

I'm trying to version my API like Stripe has. Below is given the latest API version is 2. /api/users returns a 301 to /api/v2/users /api/v1/users returns a 200 of users index at version 1 /api/v3/users returns a 301 to /api/v2/users /api/asdf/users…
maletor
  • 7,072
  • 7
  • 42
  • 63
151
votes
8 answers

Redirect From Action Filter Attribute

What is the best way to do a redirect in an ActionFilterAttribute. I have an ActionFilterAttribute called IsAuthenticatedAttributeFilter and that checked the value of a session variable. If the variable is false, I want the application to redirect…
ryanzec
  • 27,284
  • 38
  • 112
  • 169
150
votes
24 answers

How to Refresh a Component in Angular

I am working on an Angular project. I'm struggling with refresh action in a component. I would like to refresh the router's components on button click. I have refresh button when I click on it the component/router need to be refresh. I tried…
Sreehari Ballampalli
  • 3,404
  • 3
  • 12
  • 19
148
votes
5 answers

express.js - single routing handler for multiple routes in a single line

Is there a way to make this on a single function call? var todo = function (req, res){}; app.get("/", todo); app.get("/blabla", todo); app.get("/blablablabla", todo); Something like: app.get("/", "/blabla", "/blablablabla", todo ); I know this is…
Aronis Mariano
  • 2,352
  • 3
  • 22
  • 19
147
votes
3 answers

Routing with Multiple Parameters using ASP.NET MVC

Our company is developing an API for our products and we are thinking about using ASP.NET MVC. While designing our API, we decided to use calls like the one below for the user to request information from the API in XML…
CodingWithoutComments
  • 35,598
  • 21
  • 73
  • 86
139
votes
19 answers
139
votes
16 answers

Add a prefix to all Flask routes

I have a prefix that I want to add to every route. Right now I add a constant to the route at every definition. Is there a way to do this automatically? PREFIX = "/abc/123" @app.route(PREFIX + "/") def index_page(): return "This is a website…
Evan Hahn
  • 12,147
  • 9
  • 41
  • 59
137
votes
5 answers

How to get default gateway in Mac OSX

I need to retrieve the default gateway on a Mac machine. I know that in Linux route -n will give an output from which I can easily retrieve this information. However this is not working in Mac OSX(Snow Leopard). I also tried netstat -nr | grep…
SherinThomas
  • 1,881
  • 4
  • 16
  • 20
133
votes
10 answers

How do I redirect to the previous action in ASP.NET MVC?

Lets suppose that I have some pages some.web/articles/details/5 some.web/users/info/bob some.web/foo/bar/7 that can call a common utility controller like locale/change/es or authorization/login How do I get these methods (change, login) to…
adolfojp
  • 2,961
  • 4
  • 24
  • 21