Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 fix breaking changes with page params #235

Merged
merged 2 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion with-sveltekit-and-urql/src/routes/products/[slug].svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script context="module">
export const load = async ({ page: { params } }) => {
export const load = async ({ params }) => {
const { slug } = params;
return {
props: { slug },
Expand Down
79 changes: 38 additions & 41 deletions with-sveltekit/src/routes/product/[slug].svelte
Original file line number Diff line number Diff line change
@@ -1,65 +1,62 @@
<script context="module">
import { GraphQLClient } from 'graphql-request';
import { GraphQLClient } from 'graphql-request';

export async function load(ctx) {
const graphcms = new GraphQLClient(
'https://api-eu-central-1.graphcms.com/v2/ck8sn5tnf01gc01z89dbc7s0o/master',
{
headers: {}
}
);
export async function load({ params }) {
const graphcms = new GraphQLClient(
'https://api-eu-central-1.graphcms.com/v2/ck8sn5tnf01gc01z89dbc7s0o/master'
);

const { product } = await graphcms.request(
`query ProductPageQuery($slug: String!) {
const { product } = await graphcms.request(
`query ProductPageQuery($slug: String!) {
product(where: { slug: $slug }) {
name
description
price
}
}`,
{
slug: ctx.page.params.slug
}
);
{
slug: params.slug,
}
);

return {
props: {
product
}
};
}
return {
props: {
product,
},
};
}
</script>

<script>
export let product;
export let product;
</script>

<svelte:head>
<title>{product.name}</title>
<title>{product.name}</title>
</svelte:head>

<h1>{product.name}</h1>
<p>{product.description}</p>
<p>${product.price / 100}</p>

<style>
h1,
p {
text-align: center;
margin: 0 auto;
}
h1 {
font-size: 2.8em;
text-transform: uppercase;
font-weight: 700;
margin: 0 0 0.5em 0;
}
p {
margin: 1em auto;
}
@media (min-width: 480px) {
h1 {
font-size: 4em;
}
}
h1,
p {
text-align: center;
margin: 0 auto;
}
h1 {
font-size: 2.8em;
text-transform: uppercase;
font-weight: 700;
margin: 0 0 0.5em 0;
}
p {
margin: 1em auto;
}
@media (min-width: 480px) {
h1 {
font-size: 4em;
}
}
</style>