View Source Routex.Extension.RouteHelpers (Phoenix Routes Extension Framework v0.3.0-alpha.4)

Provides route helpers with support for automatic selecting alternatives routes. The helpers can be used to override Phoenix' defaults as they are a drop-in replacements.

Only use this extension when you make use of extensions generating alternative routes, as otherwise the result will be the same as the official helpers.

Configuration

# file /lib/example_web/routex_backend.ex
defmodule ExampleWeb.RoutexBackend do
  use Routex.Backend,
  extensions: [
+   Routex.Extension.RouteHelpers,
    Routex.Extension.AttrGetters
],

Phoenix < 1.7 created an alias Routes by default. You can either replace it or add an alias for RoutexHelpers. Phoenix >= 1.7 deprecated the helpers in favor of Verified Routes.

In the example below we 'override' the default Routes alias to use Routex' Route Helpers as a drop-in replacement, but keep the original helpers functions available by using alias OriginalRoutes.

# file /lib/example_web.ex
defp routex_helpers do

+ alias ExampleWeb.Router.Helpers, as: OriginalRoutes
+ alias ExampleWeb.Router.RoutexHelpers, as: Routes

end

Pseudo result

# When alternatives are created it uses auto-selection to keep the user 'in branch'.

# in (h)eex template
<a href={Routes.product_index_path(@socket, :show, product)}>Product #1</a>

# is replaced during during compilation with:
case alternative do
   nil   "/products/#{product}"
  "en"   "/products/#{product}"
  "nl"   "/europe/nl/products/#{product}"
  "be"   "/europe/be/products/#{product}"
end

Routex.Attrs

Requires

  • none

Sets

  • none

Summary

Functions

Link to this function

build_case_clauses(routes, router, suffix, args)

View Source
Link to this function

dynamic_delegate_with_arity(helper_module, fn_name, fn_args)

View Source
Link to this function

dynamic_fn_with_arity(fn_name, fn_args, opts)

View Source