Skip to content

Router macro for redirecting a request at a given path to another

License

Notifications You must be signed in to change notification settings

glennr/redirect

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

import Redirect

redirect "/path", "/new-path", :permanent

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.

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).

[
  import_deps: [:ecto, :phoenix, :redirect],
  #...
]

Installation

Add redirect for Elixir as a dependency in your mix.exs file:

def deps do
  [
    {:redirect, "~> 0.3.0"}
  ]
end

HexDocs

HexDocs documentation can be found at https://hexdocs.pm/redirect.

About

Router macro for redirecting a request at a given path to another

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir 100.0%