Skip to content

Instantly share code, notes, and snippets.

@aleclarson
Created April 22, 2022 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleclarson/1dea130b963f87d65a23c6dda140dab0 to your computer and use it in GitHub Desktop.
Save aleclarson/1dea130b963f87d65a23c6dda140dab0 to your computer and use it in GitHub Desktop.
import { route } from 'saus'
// Default route
route(() => import('./routes/UnknownPage'))
// Catch route
route('error', () => import('./routes/ErrorPage'))
//
// Matched routes
//
route('/', () => import('./routes/HomePage'))
route('/blog/:slug', () => import('./routes/BlogPost'), {
// Inline a state module since only this page uses it.
inline: req => [
blogPostModule.bind(req.slug),
],
})
// Responds to GET /blog/[slug].json
.get('.json', req => blogPostModule.load(req.slug))
// SSR-based search page (based on arbitrary user input)
// Dynamically rendered as an entry point for a search URL.
// For best UX, subsequent searches should use REST/RPC loading with CSR.
route('/search', () => import('./routes/SearchPage'), {
inline: req => [
blogSearchModule.bind(req.searchParams.get('q')),
],
})
// Responds to POST /search.json
.post('.json', req => blogSearchModule.load(req.input.q))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment