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
28
votes
1 answer

Node.js Express route naming and ordering: how is precedence determined?

Say I've got a few GET routes on my Express application: // music albums app.get('/api/albums', routes.albums.getAlbums); app.get('/api/albums/:id', routes.albums.getAlbum); app.get('/api/albums/artwork', routes.albums.getAlbumArtwork); and I…
J. Ky Marsh
  • 2,465
  • 3
  • 26
  • 32
28
votes
4 answers

How to set class based on current route name/controller

Trying to set a class based on my current controller or current route (URL Segment 1). something like That way in case I need to target separate pages for CSS specificity, it makes it easy.
Christopher Marshall
  • 10,678
  • 10
  • 55
  • 94
28
votes
4 answers

Multiple pattern in single symfony routing

How to make multiple pattern in single Symfony routing? Normally we have a routing as blog: pattern: / defaults: { _controller: AcmeBlogBundle:Blog:index, page: 1 } Is it possible to have two routing patterns? Something like blog: …
Justin John
  • 9,223
  • 14
  • 70
  • 129
27
votes
4 answers

Symfony2 bundle inheritance losing parent bundles routes

I am trying to create a simple bundle inheritance as instructed in here and ran into a problem with routes. I'm using annotations for routing. When I register my child bundle in AppKernel.php all my parent bundles routes are lost. For what I…
teemup
  • 624
  • 1
  • 8
  • 13
27
votes
1 answer

Rails: Anchor option and link_to

I have a link_to method in Rails link_to("feedback", meetings_url(:anchor => "sometext")) => The above code produces: feedback I thought anchor was supposed to prepend a hash paramter, something like…
Manjunath Manoharan
  • 4,567
  • 6
  • 28
  • 43
27
votes
5 answers

Next.js - Shallow routing with dynamic routes

When attempting shallow routing with a dynamic route in Next.js the page is refreshed and shallow ignored. Seems a lot of people are confused about this. Say we start on the following page router.push( '/post/[...slug]', …
AndrewMcLagan
  • 13,459
  • 23
  • 91
  • 158
27
votes
2 answers

How to add prefix to all node / express routes

Does anyone know of a way to configure express to add a prefix before all routes automatically? for example, currently I have: / /route1 /route2 However, I want to add a prefix like: /prefix/ /prefix/route1 /prefix/route2 Right now I need to define…
Trung Tran
  • 13,141
  • 42
  • 113
  • 200
27
votes
1 answer

Rail Routes: Controller namespaces with constraints (subdomains)

The intention is to create a subdomain to hold all the administrative function (CRUD) and the name of the subdomain is "admin". The set of controllers responsible are also organized under the namespace of "admin", i.e. the controllers are under the…
Ronnie Liew
  • 18,220
  • 14
  • 46
  • 50
27
votes
3 answers

(Vue.js) Same component with different routes

I would like to use the same component for different routes in a Vue.js application. I currently have something like this: main.js const routes = [ { path: '/route-1', name: 'route-1', component: MyComponent }, { path: '/route-2', name:…
Moisés Pio
  • 393
  • 1
  • 4
  • 11
27
votes
4 answers

Rails 3 : route a resource to another name

I have a CRUD controller for a model. Doing resources :foo allows me to route on /foo/:id, etc. for calling actions. I want add a route for a translation of 'foo' in another language. Let's say 'toto'. So I want all the /toto/:id, etc., routes to…
glmxndr
  • 45,516
  • 29
  • 93
  • 118
27
votes
2 answers

Express parameterized route conflict

I have two routes in Express 4.13 app: router.get('/:id', function (req, res) { }); router.get('/new', function(req,res){ }); But when I'm trying to access /new - I get 404, because there is no 'new' object. So how can I change set up that I can…
Nikita Unkovsky
  • 631
  • 1
  • 7
  • 13
27
votes
2 answers

Receiving POST data in Rails 4 and reading request.body

I want to send a POST request to a rails application and have it save and parse the request body in the database... My route on the receiving end is currently setup as: post '/request' => 'controller#receives_data' when I post data to this…
Davey
  • 1,093
  • 1
  • 13
  • 25
27
votes
5 answers

Angular ng-view/routing not working in PhoneGap

I'm having a problem with ngView in PhoneGap. Everything seems to be loading just fine and I can even get a basic controller working using ng-controller. But when I try to use routing with ngView, nothing happens. index.html
thewildpendulum
  • 1,255
  • 1
  • 13
  • 19
27
votes
4 answers

Simplest way to define a route that returns a 404

I've got a requirement to specify a named route in a Ruby on Rails project that returns the public/404.html page along with the 404 server response code. Leaving it blank is not an option, please don't question why, it just is :) It absolutely…
Eliot Sykes
  • 9,616
  • 6
  • 50
  • 64
26
votes
3 answers

Need a Rails route with a possible period in the :id, but also retain the optional :format

I have a Rails route that takes stock ticker symbols as the :id feeds/AMZN will return a page for Amazon feeds/AMZN.csv will return a CSV representation of the same data. But I also need to accomodate stocks like VIA.B (Viacom) so that both of…
dan
  • 43,914
  • 47
  • 153
  • 254