tinylib.places
Each screen of your app has an address: the URL's path without its leading /, plus its query
string.
tinylib.places.address: string
The address the user is on now, such as
game/abc?tab=moves, or '' on the start screen.tinylib.places.go(address: string, options?: { replace?: boolean }): void
Moves the user to
address without loading a new page. Before go returns, address is the new address and onChange functions have run.After a tap, back returns the user to the screen they left. A move with no tap, such as a redirect, takes the current screen's place, so back never returns to a screen that would only send them away again. A move to your start screen goes back to it when it's beneath, and otherwise takes the current screen's place.
JavaScript
tinylib.places.go(`game/${id}`)
Parameters
- addressstring
- The address to move to, without a leading
/. - options{ replace?: boolean }optional
- options.replacebooleanoptional
- If true, takes the current screen's place even after a tap.
Throws
- TypeError
- When
addressisn't a string, or starts with/.
tinylib.places.exit(): Promise<void>
Leaves your app for the user's Library. Draw your own Exit button and call this from its tap. It's optional: back leaves your app from the screen it opened at.
JavaScript
exitButton.onclick = () => tinylib.places.exit()
Rejects with
- refused
- With no tap in your app, or while one of Tinylib's sheets is open.
tinylib.places.onChange(fn: () => void): () => void
Calls
fn each time the address is set, even to the one the user is already on, whether by go, a link, a router's history.pushState or replaceState, the back and forward buttons, or Tinylib, as when the user joins a room from its invitation sheet.fn isn't called for the address your app opens at, so read address once at load.
JavaScript
tinylib.places.onChange(() => route(tinylib.places.address))
Parameters
- fn() => void
- Called with no arguments. Read
addressfor the new address.
Returns
- () => void
- A function that stops the calls.
Throws
- TypeError
- When
fnisn't a function.
tinylib.places.share(address: string, text?: string): Promise<void>
Opens the share sheet with
text and a link that opens your app at address. The link lets no one into a room: share tinylib.rooms.getLink for that. Works offline and for a guest.JavaScript
await tinylib.places.share(`list/${id}`, 'Our shopping list')
Parameters
- addressstring
- The address to link to, without a leading
/. - textstringoptional
- A message to send with the link.
Rejects with
- TypeError
- When
addressisn't a string.