RxAssim

RxAssim

Routes - Type-safe Phoenix routes in your JavaScript/TypeScript!

Hello Elixir community! I’m excited to announce the first release of Routes, a library that automatically generates JavaScript and TypeScript route helpers from your Phoenix router. It aims to bring the convenience and type safety of Phoenix route helpers to your frontend code.

Why Routes?

Working with Phoenix and modern JavaScript frameworks, I often found myself manually maintaining route paths in the frontend or creating custom solutions to keep frontend routing in sync with Phoenix routes. Routes solves this by:

  • :counterclockwise_arrows_button: Automatically generating route helpers from your Phoenix router
  • :memo: Providing full TypeScript support with type definitions
  • :magnifying_glass_tilted_left: Supporting live reloading during development
  • :bullseye: Handling path parameters and query strings with type safety
  • :flexed_biceps: Ensuring route parameters are correctly typed and validated

Quick Example

# In your Phoenix router
defmodule MyAppWeb.Router do
  use Phoenix.Router
  use Routes

  scope "/" do
    get "/users/:id", UserController, :show, as: :user
  end
end
// In your JavaScript/TypeScript code
import Routes from './routes';

// Type-safe route generation
const url = Routes.path('user.show', { id: 123 });
// => "/users/123"

// With query parameters
const searchUrl = Routes.path('user.index', {
  _query: { search: 'john', filter: 'active' }
});
// => "/users?search=john&filter=active"

Inertia.js Integration

If you’re using Inertia.js, Routes provides a clean way to create type-safe navigation:

<Link
  to="/users/:id"
  params={{ id: 123, _query: { tab: "profile" } }}
>
  View Profile
</Link>

Getting Started

Add to your mix.exs:

def deps do
  [
    {:routes, "~> 0.1.0"}
  ]
end

Configure in config.exs:

config :routes,
  router: MyAppWeb.Router,
  typescript: true,
  routes_path: "assets/js/routes"

Links

https://github.com/assimelha/routes

Feedback Welcome!

This is the initial release, and I’d love to hear your thoughts, suggestions, and use cases. Feel free to open issues on GitHub or contribute to the project.

Happy coding! :tada:

First 3 of 3 Posts Switch mode

BartOtten

BartOtten

Hi @RxAssim,

Always nice to see people invest time in the eco system! As for the feedback:

  1. Pardon my question but I fail to see the use case. Where does this fit in? When does a server side path need a sync with client side, which can not be (and afaik is) handled by Phoenix LiveView?*

Edit: answer myself: Inertiajs of course :slight_smile:

—-

  1. The name of the lib is a bit too close to my lib RouteX for my taste to be honest and also in the same valley as libs called ‘framework’ or ‘xml’. I would suggest a more distrinct name.

—-

  1. Maybe this can be a Routex extension? This would solve the naming issue, you can focus on the Typescript part (as processing and live regeneration is taken care of) and all features of Routex will be supported by the Typescript files (alternative routes for instance).

Kind regard,
Author of Routex

RxAssim

RxAssim

Hi @BartOtten,

  1. Yes, you could use it with Inertia, Live_svelte, Live_vue…
  2. It’s just the simplest name I could think of + this lib is mostly code that I wrote for my own projects and decided to open source it mostly as is.
  3. Seems like a good idea, but Routes is supposed to handle one thing and one thing alone which is easy routes access for frontend frameworks that use Phoenix as a backend.
Muco

Muco

Thank you for this package @RxAssim. Do you know if there’s any package that generates props types?

— All posts loaded —

Where Next?

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
387 14960 120
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
quatermain
Hello, I’m sharing my plugin here in forum after some time so it has time to mature and proof yourself. I use Claude Code daily on a pr...
New

Other Trending Topics Top

type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
bjorng
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
yureehuh
Introduction Founded in 2017 by landscape ecologist and fire mitigation expert Harry Statter, Frontline developed the first fully integra...
New

We're in Beta

About us Mission Statement