Skip to content

Commit

Permalink
Merge pull request #724 from aaronzomback/docs-default-admin-route-co…
Browse files Browse the repository at this point in the history
…nfig

docs: include hint about default admin route configuration
  • Loading branch information
Flo0807 authored Dec 19, 2024
2 parents b9a1654 + 50f92a7 commit f7c671a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions guides/get_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,46 @@ end

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

### Configure a default route

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

scope "/admin", MyAppWeb do

pipe_through :browser

backpex_routes()

# add this line
get "/", RedirectController, :redirect_to_posts

live_session :default, on_mount: Backpex.InitAssigns do
live_resources "/posts", PostLive
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 f7c671a

Please sign in to comment.