-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add examples for the
Link
navigation
- Loading branch information
Showing
5 changed files
with
90 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<template> | ||
<div class="flex flex-col gap-8"> | ||
<div class="flex gap-4"> | ||
<Link v-if="hasParams" :patch="currentPath" class="border border-white px-4 py-2 rounded"> | ||
Page {{ page }}: Patch | ||
<small>Remove params</small> | ||
</Link> | ||
<Link v-else :patch="`${currentPath}?one=1&two=hello&three=world`" class="border border-white px-4 py-2 rounded"> | ||
Page {{ page }}: Patch | ||
</Link> | ||
<Link :navigate="otherPagePath" class="border border-white px-4 py-2 rounded" | ||
>Page {{ otherPage }}: Navigate</Link | ||
> | ||
<Link href="/dead" class="border border-white px-4 py-2 rounded"> | ||
Back to Examples <small>Normal Link</small> | ||
</Link> | ||
</div> | ||
|
||
<div class="flex flex-col gap-2"> | ||
<p><strong>Page:</strong> {{ page }}</p> | ||
<div> | ||
<p><strong>Params:</strong></p> | ||
<pre v-if="params">{{ JSON.stringify(params, null, 2) }}</pre> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { Link } from "live_vue" | ||
import { computed } from "vue" | ||
const props = defineProps<{ | ||
page: string | ||
otherPage: string | ||
otherPagePath: string | ||
params?: Record<string, any> | ||
}>() | ||
const hasParams = computed(() => Object.keys(props.params ?? {})?.length) | ||
const currentPath = window.location.pathname | ||
</script> |
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
22 changes: 22 additions & 0 deletions
22
example_project/lib/live_vue_examples_web/live/navigation/page_one.ex
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule LiveVueExamplesWeb.Navigation.PageOne do | ||
use LiveVueExamplesWeb, :live_view | ||
|
||
def render(assigns) do | ||
~H""" | ||
<.header>Navigation example: Page one</.header> | ||
<.vue | ||
v-component="NavigationExample" | ||
page="One" | ||
other-page="Two" | ||
other-page-path={~p"/navigation/page_two"} | ||
params={@params} | ||
v-socket={@socket} | ||
v-ssr={false} | ||
/> | ||
""" | ||
end | ||
|
||
def handle_params(params, _uri, socket) do | ||
{:noreply, assign(socket, :params, params)} | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
example_project/lib/live_vue_examples_web/live/navigation/page_two.ex
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule LiveVueExamplesWeb.Navigation.PageTwo do | ||
use LiveVueExamplesWeb, :live_view | ||
|
||
def render(assigns) do | ||
~H""" | ||
<.header>Navigation example: Page Two</.header> | ||
<.vue | ||
v-component="NavigationExample" | ||
page="Two" | ||
other-page="One" | ||
other-page-path={~p"/navigation/page_one"} | ||
params={@params} | ||
v-socket={@socket} | ||
v-ssr={false} | ||
/> | ||
""" | ||
end | ||
|
||
def handle_params(params, _uri, socket) do | ||
{:noreply, assign(socket, :params, params)} | ||
end | ||
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