BartOtten

BartOtten

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!

https://github.com/BartOtten/routex

Most Liked

BartOtten

BartOtten

:tada: Routex v1.3.0 Changelog: Development Experience Improvements

Now with Igniter installer for super simple setup!


Routex 1.3 focuses once again heavily on improving the developer experience (DX), making installation smoother, configuration clearer, and debugging easier, particularly for projects using internationalization (i18n).

This release makes Routex an even more seamless and robust solution for handling advanced routing features, especially localization, within the Phoenix ecosystem.


:rocket: Quick Setup with routex.install

  • Simplified Installation
    The new mix routex.install task, powered by the optional Igniter dependency, significantly automates the initial setup process.
    • This eliminates the need for manual file editing, speeding up the integration of Routex into new or existing Phoenix projects. The usage guide has been updated accordingly.
    • The task performs configuration steps like setting up aliases and including common Routex extensions.

Special thanks to @ken-kost for the initial routex.install commit; not to forget @zachdaniel for Igniter itself. Community support is highly appreciated.


:warning: Clearer Error Messaging

  • Actionable Error Reports: Routex 1.3 features improved error messaging. Errors related to route compilation or configuration are now more descriptive, guiding developers to the exact issue and making troubleshooting much faster.

  • Refined Fallbacks: A few fallbacks have been added in order to print helpful error messages when a configuration error is detected. This was mostly notable when developers were in the mid of following the usage guide or disabled extensions while forgetting to remove code modifications.


:hammer_and_wrench: New Utilities

A new helper function to set the branch in the process dictionary. This can be used as dispatch target and once set will be used by verified Routes.

dispatch_targets: [{Routex.Utils, :process_put_branch, [[:attrs, :__branch__]]}]

This can be used to avoid property drilling of the @url assignment for Verified Routes in components. However it is still advised not to use it and keep things immutable. Simply pass down the @url assignment to components using Verified Routes.


:megaphone: New Callback

The create_shared_helpers/3 callback is called in the last stage. It differs from create_helpers/3 as it is called only once per extension with routes combined of all backends using the extension.

:globe_showing_europe_africa: Improved i18n/l10n Detection

  • Smarter Gettext Detection: The process for detecting localization backens has been improved. As a result Routex got rid of a macro.

Other

  • Support for using Verified Routes based on @url assignment

Upcoming: A new Example App

A new example app is (slowly) build to demonstrate Routex’ features better. The current one does not show much.



BartOtten

BartOtten

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!

BartOtten

BartOtten

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

Where Next?

Popular in Announcing Top

Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
Crowdhailer
Experimenting with this code. OK.try do user <- fetch_user(1) cart <- fetch_cart(1) order = checkout(cart, user) save_orde...
New
tmbb
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
tmbb
I’ve decided to create this topic to discuss optimization possibilities for something like Phoenix LiveView. I’ve created this topic unde...
144 10809 141
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44167 214
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 10739 134
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44608 311
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New

We're in Beta

About us Mission Statement