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
33
votes
2 answers

Regex in spring controller

I am trying to build a request filter that will only get used if it matches a pattern of the letter e, then a number. However I cannot seem to get it to work. I keep getting 400 errors every time I try something with regex. If I just use the…
zmanc
  • 5,201
  • 12
  • 45
  • 90
32
votes
9 answers

Route to static file in Play! 2.0

I'm trying to make a route to a specific static file but everything I'm trying ends with an error. I've made 3 different attempts: 1. GET /file staticFile:/public/html/file.html The error I get: Compilation error string matching regex `\z'…
Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299
32
votes
3 answers

How to dynamically call routes helper in rails?

For example, I have constructed a string called "new_work_path", now I want to call that helper as a method. I've tried send("new_work_path", vars) and calling the same send from many objects. But I don't think that I've found the right object to…
gtr32x
  • 2,033
  • 4
  • 20
  • 32
32
votes
3 answers

Next.js - router.push without scrolling to the top

I am using router from next by importing useRouter from next/router. I am trying to find a solution which will not scroll to the top of the page when I change the query of the URL. Is there any solution? I know that Link component from Next has that…
anticol
  • 487
  • 1
  • 4
  • 12
32
votes
5 answers

Adding ID and title to URL slugs in ASP.NET MVC

How do you redirect a request in ASP.NET MVC to its correct canonical version if part of the URL is missing? Using Stack Overflow as an example, the site adds the question title to the end of its routes, but uses the question ID in the route to…
wycleffsean
  • 1,377
  • 1
  • 11
  • 16
32
votes
1 answer

Rails: redirect with params

What's the best way to pass some params along with a redirect? I saw examples that said if you just add them to your redirect hash they would pass along with the request, but that doesn't seem to work anymore in Rails 3. In my example I have an…
Andrew
  • 42,517
  • 51
  • 181
  • 281
32
votes
2 answers

NodeJS Express - separate routes on two ports

I have an express server, and while building it created several "helper" functions on their own routes. I'd like those routes to be accessed on a different port. Is there anyway to do this in express? In the code below, the "/factory" route (and…
JKC
  • 741
  • 1
  • 6
  • 7
32
votes
1 answer

How to serve index.html with web api selfhosted with OWIN

Should be an easy question, just can't find the answer. I have an SPA (AngularJS) with web api which is self hosted with Owin. I use Nancy to serve the page, but I would like to get rid of Nancy and use Index.html as my single page. I've seen this…
Burjua
  • 12,506
  • 27
  • 80
  • 111
32
votes
1 answer

Rails 4 - Specify routes exclusively for development environment

Is it possible to create routes in Rails 4 that are only executed while the application is being run in dev mode?
Tolsto
  • 1,418
  • 2
  • 17
  • 45
32
votes
6 answers

play framework2: remove trailing slash from urls

In play framework 1, you could use in the routes file something like this (check documentation at http://www.playframework.org/documentation/1.2.5/routes#syntax) GET /clients/? Clients.index so that the route will match /api/clients and…
opensas
  • 60,462
  • 79
  • 252
  • 386
31
votes
1 answer

Where's root_path or root_url?

In rails, there are a lot of helpers to direct our actions, like collections_path new_member_path edit_member_path and so on. But where is the root? Is there a helper always points to my homepage?
Lai Yu-Hsuan
  • 27,509
  • 28
  • 97
  • 164
31
votes
2 answers

How to write controller tests when you override devise registration controller?

I wish to override the Devise::RegistrationsController to implement some custom functionalality. To do this, I've created a new RegistrationsController like so: # /app/controllers/registrations_controller.rb class RegistrationsController <…
David Tuite
  • 22,258
  • 25
  • 106
  • 176
31
votes
1 answer

Is it possible to bind a [routerLink] to a div? Angular 2+

I am new to Angular and I have found no clear answers on this subject no matter what I search for. This is currently working:
which directs to this function in my component: brandListRoute() { …
Daniel Bailey
  • 939
  • 5
  • 15
  • 35
31
votes
5 answers

Error: Cannot match any routes. URL Segment:

I am trying to follow this tutorial http://onehungrymind.com/named-router-outlets-in-angular-2/ but I am getting the error. EXCEPTION: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'clients' Error: Cannot match any routes.…
user4230508
31
votes
2 answers

How to display a route between two geocoords in google maps?

Possible Duplicate: J2ME/Android/BlackBerry - driving directions, route between two locations I'm just writing an App for displaying the route between two coords (lat, long) in google maps view. Displaying an single coord (even with a marker)…
poeschlorn
  • 12,230
  • 17
  • 54
  • 65