You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every page of your app can declare a `load` function in a `+page.server.js`file alongside the `+page.svelte` file. As the file name suggests, this module only ever runs on the server, including for client-side navigations. Let's add a `src/routes/blog/+page.server.js`file so that we can replace the hard-coded links in `src/routes/blog/+page.svelte`with actual blog post data:
> For the sake of the tutorial, we're importing data from `src/routes/blog/data.js`. In a real app, you'd be more likely to load the data from a database or a CMS, but for now we'll do it like this.
@@ -48,7 +48,7 @@ We can access this data in `src/routes/blog/+page.svelte` via the `data` prop:
48
48
</ul>
49
49
```
50
50
51
-
Now, let's do the same for the post page:
51
+
では、記事のページでも同じようにやってみましょう。
52
52
53
53
```js
54
54
/// file: src/routes/blog/[slug]/+page.server.js
@@ -74,7 +74,7 @@ export function load({ params }) {
74
74
<div>{@html data.post.content}</div>+++
75
75
```
76
76
77
-
There's one last detail we need to take care of — the user might visit an invalid pathname like `/blog/nope`, in which case we'd like to respond with a 404 page:
0 commit comments