routes

Ignore first segments in ASP.NET MVC Core routing

我们两清 提交于 2019-12-02 01:45:38
问题 I'm looking for a route definition that is able to match routes like: /segment/xxxx/def /segment/.../xxxx/def /segment/that/can/span/xxxx/def and be able to run the action xxxx with param `def. But this kind of route isn't allowed: [Route("/{*segment}/xxx/{myparam}")] How can it be done? 回答1: You can use a custom IRouter combined with a regular expression to do advanced URL matching such as this. public class EndsWithRoute : IRouter { private readonly Regex urlPattern; private readonly string

When to use: redirect('/') vs. redirect()->route('home') vs. redirect()->home()?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 01:44:06
When I have this named route: Route::get('/', 'IndexController@index')->name('home'); Then in any action method of any Controller; when I need to redirect to the named route home ; any of these statements redirects properly to the intended route: return redirect('/'); return redirect()->route('home'); return redirect()->home(); When to use each? What are the differences? Are there any benefits of using one over the others? As the documentation mention : When you call the redirect helper with no parameters, an instance of Illuminate\Routing\Redirector is returned, allowing you to call any

Route parameter patterns on routes with similar parameters

你。 提交于 2019-12-02 01:36:55
I have a few routes that takes a couple of UUIDs as parameters: Route::get('/foo/{uuid1}/{uuid2}', 'Controller@action'); I want to be able to verify that those parameters are the correct format before passing control off to the action: Route::pattern('uuid1', '^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$'); This works fine. However, I really don't want to repeat that pattern so many times (in the real case I have it repeated 8 times for 8 different UUID route parameters). I can't do this: Route::get('/foo/{uuid}/{uuid}', 'Controller@action'); Because that produces an error:

Customize Devise pathnames

倾然丶 夕夏残阳落幕 提交于 2019-12-02 01:30:12
I am trying to customize the urls created by the devise gem: devise_for :users, path: '', path_names: { sign_in: 'login', sign_out: 'logout', sign_up: 'signup', password: 'forgot', confirmation: 'activate', invitation: 'invite' } This works well. It creates the following routes: /login -> sessions#new /logout -> sessions#destroy /signup -> registrations#new /forgot/new -> passwords#new /forgot/edit -> passwords#edit /activate/new -> confirmations#new /activate/show -> confirmations#show /invite/new -> invitations#new /invite/accept -> invitations#edit /invite/remove -> invitations#destroy But

Ignore first segments in ASP.NET MVC Core routing

岁酱吖の 提交于 2019-12-02 01:28:43
I'm looking for a route definition that is able to match routes like: /segment/xxxx/def /segment/.../xxxx/def /segment/that/can/span/xxxx/def and be able to run the action xxxx with param `def. But this kind of route isn't allowed: [Route("/{*segment}/xxx/{myparam}")] How can it be done? You can use a custom IRouter combined with a regular expression to do advanced URL matching such as this. public class EndsWithRoute : IRouter { private readonly Regex urlPattern; private readonly string controllerName; private readonly string actionName; private readonly string parameterName; private readonly

Can't find a route with an underscore or doesn't treat it properly

点点圈 提交于 2019-12-02 01:08:06
I have this in routes: Rails.application.routes.draw do namespace :api do namespace :v3_4 do # ..... And the controller app/controllers/api/v3_4/base_controller module Api module V3_4 class BaseController < ApplicationController # ...... end end end And app/controllers/api/v3_4/another_controller module Api module V3_4 class AnotherController < ApplicationController end end end rake routes: Prefix Verb URI Pattern Controller#Action api_v3_4_test GET /api/v3_4/test(.:format) api/v3_4/base#test api_v3_4_one GET|OPTIONS /api/v3_4/one(.:format) api/v3_4/another#one api_v3_4 GET|OPTIONS /api/v3_4

Angular - UI Router Routes - HTML5 Mode

你离开我真会死。 提交于 2019-12-02 01:05:21
I'm trying to use HTML5 push state links with my Angular app. What I have is a series of routes similar to the following $stateProvider.state('product', { url: '/product/:productCode', templateUrl: 'product/product.html', controller: 'ProductCtrl' } }); This works when I navigate to [host]/#/product/ABC123 - It displays the url in the browser as /product/ABC123, then when I start clicking through to my other routes (using ui-sref) everything works as expected. However - I'd like the ability to both refresh the browser, and remain in the same state, as well as be able to copy and paste that

Rails 3 Problem with Routes Constraint

本秂侑毒 提交于 2019-12-02 00:57:19
I'm trying to make it so that I can have a urls like this: /events /events/sunday # => The day is optional However, it doesn't seem to be working even though I know it is getting called. It is at the bottom of my routes file. match '/:post(/:day_filter)' => 'posts#index', :as => post_day_filter, :constraints => DayFilter.new class DayFilter def initialize @days = %w[all today tomorrow sunday monday tuesday wednesday thursday friday saturday] end def matches?(request) return @days.include?(request.params[:day_filter]) if request.params[:day_filter] true end end Here is my rake routes output:

Setting index route in Symfony 2

Deadly 提交于 2019-12-02 00:19:46
I've got Symfony2 installed, and a mostly working site, the only issue is I don't know how to set a default route. Currently, I access my index and other routes with the following URLs: www.example.com/app_dev.php/index www.example.com/app_dev.php/example_route I'd like to have www.example.com default to the index route, so I can get the same results with the following URLs: www.example.com www.example.com/example_route I'm running lighttpd as my web server. How can I configure lighttpd/Symfony2 to do this? Just create a route that maps to the / pattern : # app/config/routing.yml homepage:

Why is it so hard to get route values outside controller context?

两盒软妹~` 提交于 2019-12-01 23:37:45
I don't understand what's the deal behind this, why is it so easy to get route values inside Request of controller but nearly impossible to do the same thing on HttpContext.Current.Request ? Maybe I just don't know a better way and it exists. Can someone confirm that this is the only way to get route data outside controller? Example [Route("{id}"), HttpGet] public IHttpActionResult Test() { // Simple and easy var route1 = Request.GetRouteData().Values["id"]; // Wat. This is also ~6 times slower var routeValues = (IHttpRouteData[]) HttpContext.Current.Request.RequestContext.RouteData.Values["MS