Effective Routing Techniques
We’ve spent a lot of time covering background information. I know those topics aren’t always the most exciting, but now that we’ve covered them, we can get to the real fun. Up until now, we’ve only briefly touched on adding new routes by creating a directory inside src/routes/
with the desired route name and adding a +page.svelte
file inside of it. We also briefly looked into creating server pages. But, of course, routing isn’t always so simple. How do we build out an application programming interface (API)? How do we create a consistent user interface (UI) throughout our application without duplicating styles on each page? What happens when our application throws an error?
In this chapter, we will answer some of those questions by discussing some core points about routing within the context of SvelteKit. First, we’ll look at how we can create new pages with dynamic content. Then, we’ll take a closer look...