Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mathieuprog/redirect
Router macro for redirecting a request at a given path to another
https://github.com/mathieuprog/redirect
elixir elixir-lang plug redirect router
Last synced: about 2 months ago
JSON representation
Router macro for redirecting a request at a given path to another
- Host: GitHub
- URL: https://github.com/mathieuprog/redirect
- Owner: mathieuprog
- License: apache-2.0
- Created: 2019-12-03T17:17:38.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-22T03:29:00.000Z (over 1 year ago)
- Last Synced: 2024-09-16T02:49:21.070Z (4 months ago)
- Topics: elixir, elixir-lang, plug, redirect, router
- Language: Elixir
- Size: 12.7 KB
- Stars: 20
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Redirect
**Redirect** provides a macro for your router to redirect a request at a given
path to another.In your `router.ex` file, use the `redirect/3` macro to redirect a request:
```elixir
import Redirectredirect "/path", "/new-path", :permanent, preserve_query_string: true
```⚠️ `redirect/3` doesn't work inside scopes (`scope/2`/`scope/3`/`scope/4`)
The third argument passed to `redirect/3` must be either `:permanent` or
`:temporary`. This setting sets the HTTP status code to 301 or 302 respectively.The fourth optional argument allows to specify whether the query string must be preserved in the
target URL or not (defaults to false).Note that `Plug.Conn` will be halted right after redirecting.
You may also import `:redirect`'s formatter configuration by importing
`redirect` into your `.formatter.exs` file (this allows for example to keep
`redirect "/path", "/new-path", :permanent` without parentheses when running `mix format`).```elixir
[
import_deps: [:ecto, :phoenix, :redirect],
#...
]
```## Installation
Add `redirect` for Elixir as a dependency in your `mix.exs` file:
```elixir
def deps do
[
{:redirect, "~> 0.4.0"}
]
end
```## HexDocs
HexDocs documentation can be found at [https://hexdocs.pm/redirect](https://hexdocs.pm/redirect).