Routex - build powerful Phoenix routes: localize, customize, and innovate

This powerful library works together with Phoenix Router to provide the ultimate routing solution. It simplifies route manipulation, giving you the control you need to handle even the most demanding routing requirements.

Routex comes with extensions for internationalization (i18n), localization (l10n), translated (multilingual) URLs, alternative routes generation and many more. Its modern extensible architecture enables you to easily build custom solutions that work harmoniously with other extensions.

Top Features and Benefits

  • No dependencies, no state: Routex is unique in not requiring any external dependency and works by default without proces state.

  • Powerful transformations: Routex supports advanced route transformations, including everything needed for internationalization (i18n) and localization (l10n).

  • Extension driven: Being extension driven, Routex can be adapted to your specific needs. It’s architecture allows you to write your own routing features without having to worry about breaking existing functionality. Routex ships with extensions covering a wide range of use cases. Have a look at a summary of extensions.

  • Optimized for performance: Built to fit between route configuration and route compilation. Routex enhances Phoenix routing without adding runtime overhead, ensuring that applications run as fast as ever.

  • Detailed documentation: Comprehensive, well-organized documentation provides clear guidance on installation, configuration, and best practices, making Routex approachable for developers at all levels. For example: If you are interested in internationalization (i18n) or localization (l10n) have a look at the Localized Routes Guide.

Drop-in for Phoenix Routes and Cldr Routes

Routex can be configured as a drop-in replacement for both the native Phoenix Routes and Cldr Routes (using an adapter extension). You can give it a try without modifications to your templates, paths and links!

Installation and usage

Usage Guide - requirements and installation. instructions.

Documentation - from step-by-step guides till in-depth explanations.

Give it a try!

Online demo - have a look or get the code.

Links

Hex
Documentation
Source

Route solutions comparison
How Routex and Phoenix Router work together

Upcoming:

  • LiveView lifecycle hooks and Plug callbacks
  • Rewritten Usage guide
  • Installation using Igniter
  • Param translation (?)

If you need something in particular, send a message and we’ll have a look!

37 Likes

Documentation is a key part of any library, so I took some time to refine and improve its structure. Huge thanks to the authors of ExDoc for making it all possible! Flexibility is the way to go :wink:

Old

New :fire:

5 Likes

Today I took the opportunity to resolve a significant shortcoming I had encountered with the extensions’ documentation. Although the extensions are supposed to operate in concert, the available documentation did not offer clear guidance on their integration. I am delighted to report that I have successfully published my solution to this issue.

The extensions’ co-operation is not exclusive. They are happy to co-operate with any third-party extension.


Both the Alternatives and Translations extensions are used for localization. The guide is now clearly linked in the documentation.


The documentation of the AlternativeGetters extension now includes an example of how it is used in templates.


The Cldr adapter is convenient for those using Cldr, but one might need more flexibility. The documentation now clearly states (how) you can “eject” the adapter.


Happy doc browsing!

7 Likes

Routex 1.1.0 Release Notes

Made possible by the invaluable feedback of @KristerV!

Features

- Provide assigns directly in conn.
Assigns are embedded in routes for easy access in ‘dead views’.
- Add function to print critical messages.
Some messages should never be missed. This function displays message in a very visible way. Flashy


Fixes

- Match patterns fail on trailing slash.
Phoenix does not distinguish paths with- and without trailing slash while matching routes. We align our matching behavior.
- Undefined on_mount/4, silent missing attrs/1.
The check if helper attrs/1 exists could fail without warning. Missing such helper would cause on_mount/4 not to be generated.

Documentation

What’s next

Bridging the gap
There is still a gap to be filled between localized/translated routes and localized/translated pages. The next release will focus on bridging the gap by featuring extensions/hooks to set state for other libs such as Gettext and Cldr.

Improved Installation and Usage documentation
Currently the USAGE guide starts of with a minimal configuration and expects developers to add extensions to the extension list themselves. Providing a sane default set with example extension configuration would speed up initial setup.

Simple by default, powerful when needed.

Extract some core functionality to extensions
Some things just don’t belong in the core and would happily live separate, Less code in core, less chance of bugs in core!


Happy usage!

6 Likes

Preview of the day

A new version of Routex is on it’s way, with less compilation pitfalls, major compilation speedup and a handful other features.

As the next release would be about “bridging the gap between compile time and run time”: here is small preview of 3 new extensions working in tandem
.

LiveViewHooks and Plugs allow extensions to hook into Phoenix runtime. SimpleLocale (among others) makes use of these to do just that.


to get localization over the bridge with a one-line change! (and translation files)

It works with multiple other packages such as Gettext, Cldr and Fluent.

rtx720

The SimpleLocale it aimed to speedup localization by providing a mini localization set. Yet, we never forget to make things customizable (defaults will be fine for 99% though)

Simple by default, but powerful when needed :slight_smile:

  # only a subset of options
    region_sources: [:accept_language, :attrs],
    region_params: ["region"],
    language_sources: [:query, :attrs],
    language_params: ["language"],
    locale_sources: [:query, :session, :accept_language, :attrs],
    locale_params: ["locale"]
4 Likes

An old topic was re-opened to discuss the upcoming 1.2.0. for which a release candidate has just been released to Hex.

Hope to get some constructive feedback on the major release with minor version bump.

2 Likes

Version 1.2 of Routex has been released a few months ago, but never got a proper release announcement. So how would you know about it’s new nifty features?

Routex 1.2

I’m thrilled to announce Routex 1.2.0, a major update that brings zero‑config internationalization (i18n) and and localization (l10n) to your Phoenix apps. It plugs straight into Cldr, Gettext, or Fluent and eliminates the boilerplate of manual locale plugs and translation hooks.

Summary

  • Simplified localization

  • Comprehensive runtime integration

  • Enhanced developer tools

  • Improved Reliability and Performance

Routex 1.2 lowers the bar of Phoenix localization

I am happy to announce Routex arguably has the most comprehensive localized routes system for Phoenix, the most customizable locale detection and yet the easiest setup due to auto-detection of third-party localization packages.

  1. Zero-Config Localization with Multilingual Routing

Building multilingual Phoenix sites used to mean scattering locale detection, LiveView hooks, and dynamic-route logic throughout your code. Routex 1.2.0 replaces all that with a single, centralized configuration. Your router stays clean, localization is applied at compile time, and runtime dispatching seamlessly handles any additional needs—no extra wiring required.

The new Localization system is a game-changer automatically detecting your existing Phoenix localization setup and making everything work out of the box.

Not to say there is no customization. Just as an example:

# lib/my_app_web/routex_backend.ex

# Override auto-detected locale settings for route generation
locales: ["en-US", "fr-FR", "nl-BE": %{language_display_name: "DUTCH"}}],
default_locale: "en-US",

# Customize URL generation: results in "/", "/world", "/france", "/netherlands", "/belgium"
locale_prefix_sources: :region_display_name

# Customize region detection order: fixed to route attribute, no override possible
region_sources: [:route],

# Customize language detection order, 3 possible overrides (over the route)
language_sources: [:query, :session, :accept_language, :route]

2. Enhanced integration with other libraries

For scenarios requiring integration with other third-party libs, Routex 1.2.0 introduces runtime dispatch targets through the Routex.Extension.RuntimeDispatcher extension. The dispatch targets are automatically called using a Plug and Liveview events using a LiveView Lifecycle Hook.

dispatch_targets: [
    # Set Gettext locale using detected :language attribute (this is a default)
    {Gettext, :put_locale, [[:attrs, :runtime, :language]]},

    # Custom dispatch using routes :region attribute
    {MyModule, :set_region, [[:attrs, :route, :region]]},
]

3. Automated LiveView lifecycle hooks and plugs

Two new extensions add support for the detection and auto-enabling of Plugs and LiveView Livecycle Hooks provided by other extensions. This seamless integration improves the overall developer experience (DX) by reducing the friction of additional plug and hook configuration.

4. A Better Development Experience

We’ve completely overhauled the development experience.

  • Crystal-clear error messages

  • Built-in AST inspection for debugging

Clearer Error Messages

Configuration issues now trigger clearer error messages. Instead of encountering a full stacktrace, you receive concise guidance to help pinpoint and resolve common mistakes.

Furthermore, a new configuration setting allows developers to output the generated code for inspection. This additional transparency can be valuable for diagnosing issues with the extension-generated helper functions.

Improved Performance

Several improvements have been made to the Routex pre-processing engine for better compilation. The revamped processing model brings compile‑time optimizations, and increases the amount of supported routes to multiple hundreds.

Build-in extensions have been recrafted for reduced generated code and enhanced performance thanks to Elixir’s robust pattern matching and function call optimizations -ensuring that your app remain both fast and reliable.

Demo time!

Have a look at the demo or a

For more details, visit the full release notes.

Cheers,
Bart

7 Likes

13 posts were split to a new topic: Compilation error verified path: (ArgumentError) paths must begin with /