_default.page.*

The _default.page.* files allow us to define hooks and settings that apply to all pages.

For example, we usually define a render() hook in _default.page.server.js in order to define how our pages are rendered to HTML.

// /renderer/_default.page.server.js
// Environment: Node.js

// This `render()` hook applies to all our pages
export async function render(pageContext) {
  return escapeInject`<!DOCTYPE html>
    <html>
      <head>
        <title>My SSR App</title>
      </head>
      <body>
        <div id="root">${dangerouslySkipEscape(renderToHtml(pageContext.Page))}</div>
      </body>
    </html>`
}

_default.page.route.js

The _default.page.route.js file allows us to control the routing process, see _default.page.route.js.

Multiple defaults

There can be multiple defaults:

marketing/renderer/_default.page.server.js
marketing/renderer/_default.page.client.js
marketing/pages/index.page.js
marketing/pages/about.page.js
marketing/pages/jobs.page.js

admin-panel/renderer/_default.page.server.js
admin-panel/renderer/_default.page.client.js
admin-panel/pages/index.page.js

The marketing/_default.page.* files apply as default to marketing/**/*.page.js, while admin-panel/_default.page.* apply as default to admin-panel/**/*.page.js.