# Making the web Svelter with SvelteKit ### Part 8 - Adding the photo route [Back to part 7](part7_slides.html) --- ## Designing the layouts
--- ## Refactoring - We need to move some code in order to achieve this - First we need to rename src/routes/album/[albumid]/+page.js to src/routes/album/[albumid]/+layout.js - Next, we need to delegate the selected photo view to a subroute using the ***slot***-element - If no photo is selected (user is at the album/[albumid] route), redirect to the first photo in the album --- ## The updated +layout.svelte ```svelte [6-12, 20]
<- Tilbake
{#each data.album.images as image}
{/each}
``` --- ## Update the album/[albumid]/+page.svelte - Show a temporary page before redirecting ```svelte []
Velkommen til {$page.params.albumid} albumet!
``` --- ## Adding a dynamic route for photos - Add a static route /src/routes/album/[albumid]/photo - Add a dynamic route /src/routes/album/[albumid]/photo/[photoid] --- ## Loading data from the parent in /src/routes/album/[albumid]/photo/[photoid]/+page.js ```svelte [] export async function load({parent, params}) { const data = await parent(); let album = await data.albums.find((album) => album.caption === params.albumid); let photo = await data.photos.find((photo) => photo.id = params.photoid); return { album: album, photo: photo}; } ``` --- ## Showing the photo in /album/[albumid]/photo/[photoid]/+page.svelte ```svelte []
``` --- ## Onwards [part 9](part9_slides.html)