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

sasajuric
I’d like to announce a small library called boundaries. This is an experimental project which explores the idea of enforcing boundaries ...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 19483 141
New
bradley
I’ve been working with Claude Code extensively and absolutely love it. However, I’ve come across the challenge of managing configuration ...
New
Eiji
ExApi is a library that I’m developing now and hope release soon This library will allow to: list all apis list all api implementation...
New
blatyo
The best overview for how things are tied together is this presentation. Modules and functions are pretty well documented at this point, ...
New
nikokozak
Hello all, I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
cjen07
parameterized pipe in elixir: |n> edit: negative index in |n> and mixed usage with |> are supported example: use ParamPipe ...
New
Jskalc
Hi! Today, after a couple weeks of development I’ve released v0.1 of LiveVue. It’s a seamless integration of Vue and Phoenix LiveView, i...
New
marcuslankenau
I feel kind of stuck with the absence of a proper xml library for Elixir. Currently I use SweetXML which was ok for me more or less to pa...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48475 226
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127536 1222
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54250 245
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement