View Source mix exinertia.setup.routes (exinertia v0.8.2)
Configures Routes in your Phoenix project.
This installer automates the basic steps for integrating Routes into your Phoenix project. It makes changes similar to the following:
- Add a "use Routes" call to your Phoenix router.
- Configure Routes in config/config.exs with your router module, along with options to output TypeScript definitions and customize the routes path.
- [Optional] Remind you to add the Routes.Watcher to your supervision tree in development so that routes are automatically regenerated when your router file changes.
Configuration
Add Routes to your Phoenix Router:
In your router file (e.g.,
lib/your_app_web/router.ex
), adduse Routes
:defmodule YourAppWeb.Router do use Phoenix.Router use Routes # Add this line # Your routes... end
Configure Routes in
config/config.exs
:Specify your router module and optional settings:
config :routes, router: YourAppWeb.Router, typescript: true, # Enable TypeScript output, defaults to false routes_path: "assets/js/routes" # Optional, defaults to "assets/js"
[Optional] Enable live reloading of routes:
To automatically regenerate routes when your router file changes during development, add the
Routes.Watcher
to your application's supervision tree inlib/your_app/application.ex
:def start(_type, _args) do children = [ # ... other children ] # Add the Routes.Watcher in development environment children = if Mix.env() == :dev do children ++ [{Routes.Watcher, []}] else children end opts = [strategy: :one_for_one, name: YourApp.Supervisor] Supervisor.start_link(children, opts) end
Example
mix routes.install