Skip to content

Commit

Permalink
refactor: ♻️ replace page with params
Browse files Browse the repository at this point in the history
breaking change in requst.origin/path/query, see sveltejs/kit#3126

all places where page is used in a load function
  • Loading branch information
spences10 committed Jan 1, 2022
1 parent 9f08c98 commit 3b4fed7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/routes/[yyyy]/[mm]/[dd]/[slug]/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
https://github.com/rodneylab/sveltekit-blog-mdx/blob/dev__redirect/src/routes/%5Byear%5D/%5Bmonth%5D/%5Bday%5D/%5Bslug%5D/index.svelte
-->
<script context="module">
export const load = async ({ page }) => {
const { slug } = page.params
export const load = async ({ params }) => {
const { slug } = params
return {
status: 301,
redirect: `/posts/${slug}`,
Expand Down
12 changes: 8 additions & 4 deletions src/routes/__error.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<script context="module">
export const load = async ({ error, status, page: { path } }) => {
export const load = async ({
error,
status,
url: { pathname },
}) => {
return {
props: { error, status, path },
props: { error, status, pathname },
}
}
</script>

<script>
export let error, status, path
export let error, status, pathname
</script>

<svelte:head>
Expand All @@ -18,7 +22,7 @@
<h1>{status}</h1>
<p>{error.message}</p>
<p>That's a nop! 😭</p>
<p>It looks like <code>{path}</code> doesn't exist</p>
<p>It looks like <code>{pathname}</code> doesn't exist</p>
<p>
Maybe check out the <a href="/posts">posts</a> page? Or go to the
<a href="/">home</a> page.
Expand Down
2 changes: 1 addition & 1 deletion src/routes/__layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
})
})
$: $page.path, browser && Fathom.trackPageview()
$: $page.pathname, browser && Fathom.trackPageview()
</script>
<div class="flex flex-col min-h-screen">
Expand Down
2 changes: 1 addition & 1 deletion src/routes/now.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script context="module">
export const load = async ({ page }) => {
export const load = async () => {
try {
const Copy = await import(`../../copy/now.md`)
return {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/posts/[slug].svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @type {import('@sveltejs/kit').Load}
*/
export const load = async ({ page: { params } }) => {
export const load = async ({ params }) => {
const { slug } = params
const post = getPosts().find(post => slug === post.metadata.slug)
if (!post) {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/tags/[slug]/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import { description, name, website } from '@lib/info'
import { ogImageUrl } from '@lib/og-image-url-build'
export const load = async ({ page }) => {
const { slug } = page.params
export const load = async ({ params }) => {
const { slug } = params
const { postsByTag } = await getPostTags()
return {
props: {
Expand Down

0 comments on commit 3b4fed7

Please sign in to comment.