2023-03-07 07:17:42 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
const LinkWithTrailingSlash = defineNuxtLink({
|
|
|
|
trailingSlash: 'append'
|
|
|
|
})
|
|
|
|
const LinkWithoutTrailingSlash = defineNuxtLink({
|
|
|
|
trailingSlash: 'remove'
|
|
|
|
})
|
|
|
|
const links = [
|
|
|
|
'/',
|
|
|
|
'/nuxt-link/trailing-slash',
|
|
|
|
'/nuxt-link/trailing-slash/',
|
|
|
|
'/nuxt-link/trailing-slash?test=true&thing=other/thing#thing-other',
|
|
|
|
'/nuxt-link/trailing-slash/?test=true&thing=other/thing#thing-other',
|
|
|
|
{ name: 'nuxt-link-trailing-slash' },
|
|
|
|
{ query: { 'with-state': 'true' }, state: { foo: 'bar' } },
|
2024-01-31 11:11:16 +00:00
|
|
|
{ query: { 'without-state': 'true' } },
|
|
|
|
'https://example.com/page.html'
|
2023-05-09 17:08:07 +00:00
|
|
|
] as const
|
2023-03-07 07:17:42 +00:00
|
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
const windowState = computed(() => {
|
2023-09-19 21:26:15 +00:00
|
|
|
if (import.meta.client) {
|
|
|
|
console.log(route.fullPath)
|
|
|
|
return window.history.state.foo
|
|
|
|
}
|
|
|
|
return ''
|
2023-03-07 07:17:42 +00:00
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
2024-01-31 11:11:16 +00:00
|
|
|
<h2>window state</h2>
|
2023-03-07 07:17:42 +00:00
|
|
|
<div data-testid="window-state">
|
|
|
|
<ClientOnly>
|
|
|
|
{{ windowState }}
|
|
|
|
</ClientOnly>
|
|
|
|
</div>
|
2024-01-31 11:11:16 +00:00
|
|
|
<h2>Links With Trailing Slash</h2>
|
2023-03-07 07:17:42 +00:00
|
|
|
<ul>
|
2023-11-09 17:01:13 +00:00
|
|
|
<li
|
|
|
|
v-for="(link, index) in links"
|
|
|
|
:key="index"
|
|
|
|
>
|
|
|
|
<LinkWithTrailingSlash
|
|
|
|
:to="link"
|
|
|
|
class="link-with-trailing-slash"
|
|
|
|
>
|
|
|
|
<LinkWithTrailingSlash
|
|
|
|
v-slot="{ href }"
|
|
|
|
custom
|
|
|
|
:to="link"
|
|
|
|
>
|
2023-03-07 07:17:42 +00:00
|
|
|
{{ href }}
|
|
|
|
</LinkWithTrailingSlash>
|
|
|
|
</LinkWithTrailingSlash>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<hr>
|
2024-01-31 11:11:16 +00:00
|
|
|
<h2>Links Without Trailing Slash</h2>
|
2023-03-07 07:17:42 +00:00
|
|
|
<ul>
|
2023-11-09 17:01:13 +00:00
|
|
|
<li
|
|
|
|
v-for="(link, index) in links"
|
|
|
|
:key="index"
|
|
|
|
>
|
|
|
|
<LinkWithoutTrailingSlash
|
|
|
|
:to="link"
|
|
|
|
class="link-without-trailing-slash"
|
|
|
|
>
|
|
|
|
<LinkWithoutTrailingSlash
|
|
|
|
v-slot="{ href }"
|
|
|
|
custom
|
|
|
|
:to="link"
|
|
|
|
>
|
2023-03-07 07:17:42 +00:00
|
|
|
{{ href }}
|
|
|
|
</LinkWithoutTrailingSlash>
|
|
|
|
</LinkWithoutTrailingSlash>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<hr>
|
2024-01-31 11:11:16 +00:00
|
|
|
<h2>Nuxt Link</h2>
|
2023-03-07 07:17:42 +00:00
|
|
|
<ul>
|
2023-11-09 17:01:13 +00:00
|
|
|
<li
|
|
|
|
v-for="(link, index) in links"
|
|
|
|
:key="index"
|
|
|
|
>
|
|
|
|
<NuxtLink
|
|
|
|
:to="link"
|
|
|
|
class="nuxt-link"
|
|
|
|
>
|
|
|
|
<NuxtLink
|
|
|
|
v-slot="{ href }"
|
|
|
|
custom
|
|
|
|
:to="link"
|
|
|
|
>
|
2023-03-07 07:17:42 +00:00
|
|
|
{{ href }}
|
|
|
|
</NuxtLink>
|
|
|
|
</NuxtLink>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<hr>
|
2024-01-31 11:11:16 +00:00
|
|
|
<h2>Router Link</h2>
|
2023-03-07 07:17:42 +00:00
|
|
|
<ul>
|
2023-11-09 17:01:13 +00:00
|
|
|
<li
|
|
|
|
v-for="(link, index) in links"
|
|
|
|
:key="index"
|
|
|
|
>
|
|
|
|
<RouterLink
|
|
|
|
:to="link"
|
|
|
|
class="router-link"
|
|
|
|
>
|
|
|
|
<RouterLink
|
|
|
|
v-slot="{ href }"
|
|
|
|
custom
|
|
|
|
:to="link"
|
|
|
|
>
|
2023-03-07 07:17:42 +00:00
|
|
|
{{ href }}
|
|
|
|
</RouterLink>
|
|
|
|
</RouterLink>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</template>
|