-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,37 @@ | ||
defmodule DemoWeb.PageController do | ||
use DemoWeb, :controller | ||
use DemoWeb, :live_view | ||
|
||
def home(conn, _params) do | ||
# The home page is often custom made, | ||
# so skip the default app layout. | ||
render(conn, :home, layout: false) | ||
@spec render(any()) :: none() | ||
def render(assigns) do | ||
inspect(assigns) | ||
assigns = assign(assigns, :page, assigns[:page] || 1) | ||
|
||
~H""" | ||
page <%= @page %> | ||
<br /> | ||
<br /> | ||
<.link style="color: blue; text-decoration: underline" patch={"?page=#{@page+1}"}> | ||
goto page <%= @page + 1 %> | ||
</.link> | ||
<br /> | ||
<br /> | ||
<pre> | ||
STR: | ||
1. open dev console | ||
2. navigate to page 2 | ||
3. use browser backward | ||
observe that it prints the stored user data | ||
4. use browser forward to get back to this page | ||
observe that it forgot stored user data | ||
</pre> | ||
""" | ||
end | ||
|
||
def handle_params(%{"page" => page}, _url, socket) do | ||
socket = assign(socket, page: String.to_integer(page)) | ||
{:noreply, socket} | ||
end | ||
|
||
def handle_params(_params, _url, socket), do: {:noreply, socket} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters