/state.json endpoint
aleclarson opened this issue · 1 comments
aleclarson commented
This feature was mentioned in #2, but will be implemented before then.
Here's the original proposal:
Every route has a generated
state.json
module. For example, you can fetch/foo/state.json
to get the client state for the/foo
page. This client state contains therouteModuleId
androuteParams
by default, in addition to any state set by the renderer that generated the page's HTML.Similar to #1, there will be
fetchClientState
andapplyClientState
helpers exported bysaus/client
, which can be used in your client-side router.
Amendments since then include:
- Omit
applyClientState
helper for now - Rename
fetchClientState
toloadClientState
- State returned by
loadClientState
is (indefinitely) cached locally - The initial state included in the page HTML is injected into the cache
- The
state.json
module works in both SSG and SSR scenarios
Future
Improvements we could make in the future include:
- Special
ttl
property in state object would define how long to cache it for
aleclarson commented
Implemented in next
branch
Instead of using [page]/state.json
, we're using [page].html.js