Skip to content

Commit

Permalink
docs: update default route description
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronzomback committed Dec 19, 2024
1 parent e077d4a commit d9bc8a8
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions guides/get_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,27 @@ end

This macro will add the required routes for the `PostLive` module. You can now access the `PostLive` LiveResource at `/admin/posts`.

> Hint: To configure a default redirect route for `/admin` we recommend to create a redirect controller like the following:
### Configure a default route

In your `router.ex` file:
To make a default route for `/admin` we recommend creating a redirect controller such as the following:

In `my_app_web/controller` create a file named `redirect_controller.ex`:

```elixir
# redirect_controller.ex

defmodule MyAppWeb.RedirectController do
use MyAppWeb, :controller

def redirect_to_posts(conn, _params) do
conn
|> Phoenix.Controller.redirect(to: ~p"/admin/posts")
|> Plug.Conn.halt()
end
end
```

And configure in your `router.ex` file:

```elixir
#router.ex
Expand All @@ -339,30 +357,14 @@ scope "/admin", MyAppWeb do
backpex_routes()

get "/", RedirectController, :redirect_to_posts

live_session :default, on_mount: Backpex.InitAssigns do
# add this line
live_resources "/posts", PostLive
end
end
```

And in `my_app_web/controller` create a file named `redirect_controller.ex`:

```elixir
# redirect_controller.ex

defmodule MyAppWeb.RedirectController do
use MyAppWeb, :controller

def redirect_to_posts(conn, _params) do
conn
|> Phoenix.Controller.redirect(to: ~p"/admin/posts")
|> Plug.Conn.halt()
end
end
```

## Remove default background color

If you start with a new Phoenix project, you may have a default background color set for your body tag. This conflicts with the background color of the Backpex `app_shell`.
Expand Down

0 comments on commit d9bc8a8

Please sign in to comment.