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!

35 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:

4 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!

6 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!

5 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"]
3 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.

1 Like