chapter sixteen

16 Sapper applications

 

This chapter covers:

  • The file structure of Sapper projects
  • Page routes
  • Page layouts
  • Handling errors
  • Running on both server and client
  • Fetch API wrapper
  • Preloading data needed by pages
  • Prefetching for faster page loads
  • Code splitting

The previous chapter provided a taste of using Sapper. Now it’s time to dig deeper into a series of topics covering its most commonly used features.

While it is not technically necessary to understand the purpose of every directory and file in a Sapper project, being exposed to this information will provide a better understanding of what Sapper provides and how the pieces fit together. By the time you’ve finished this chapter, you will feel comfortable navigating a Sapper project.

Sapper routes greatly simplify creating apps where users can navigate to multiple “pages”, like the three pages in the Shopping app from chapter 15.

Page layouts are Svelte components that provide a common layout to a set of pages. A scenario supported by page layouts is when multiple pages in an app have common sections such a header, footer, or left nav. We will explore implementing custom page layouts.

16.1  Sapper file structure

16.2  Page routes

16.3  Page layouts

16.4  Handling errors

16.5  Running on both server and client

16.6  Fetch API wrapper

16.7  Preloading

16.8  Pre-fetching

16.9  Code splitting

16.10  Building the Travel Packing app

16.11  Summary