just.Router()
Methods
changeState(action, url) → {boolean}
Call a window.history's function if available. Otherwise, change the current url using location.hash and prepending a hashbang (#!) to the url state.
Parameters:
Name | Type | Description |
---|---|---|
action | string | "pushState" or "replaceState". |
url | url | A same-origin url. |
Returns:
`false` if something fails, `true` otherwise.
- Type
- boolean
pushState(url) → {boolean}
Do a history.pushState calling just.Router.changeState.
Parameters:
Name | Type | Description |
---|---|---|
url | url | just.Router.changeState's url param. |
Returns:
just.Router.changeState's returned value.
- Type
- boolean
replaceState(url) → {boolean}
Do a history.replaceState calling just.Router.changeState.
Parameters:
Name | Type | Description |
---|---|---|
url | url | just.Router.changeState's url param. |
Returns:
just.Router.changeState's returned value.
- Type
- boolean
change(action, url, data, eventInit)
Do a just.Router.changeState and trigger an action if it succeds.
Parameters:
Name | Type | Description |
---|---|---|
action | string | A valid just.Router.changeState's action. |
url | url | The new url. |
data | Any | Some data. |
eventInit | CustomEventInit | Options for the event. |
push(url, data)
Trigger a "pushState" action by calling just.Router#change.
Parameters:
Name | Type | Description |
---|---|---|
url | url | just.Router#change's url argument. |
data | Any | just.Router#change's data argument. |
CustomEventInit | just.Router#change's eventInit argument. |
replace(url, data)
Trigger a "replaceState" action by calling just.Router#change.
Parameters:
Name | Type | Description |
---|---|---|
url | url | just.Router#change's url argument. |
data | Any | just.Router#change's data argument. |
CustomEventInit | just.Router#change's eventInit argument. |
route(id, path, handler, optionsnon-null)
Define a route, attach listeners (for "popstate" and custom events), and trigger an "init" event.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | string | Some unique string to identify the current route. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
path | string or RegExp or object | A value that will match the current location. A string/RegExp is the same as passing {"pathname": string/RegExp}. An object must contain any window.location's keys, like "search", "hash", ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
handler | function | Some function that will be called when the route matches the current url. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
options | object | Properties
|
trigger(action, data, eventInit)
Call a custom action on the current route by triggering a CustomEvent on each given route.
Parameters:
Name | Type | Description |
---|---|---|
action | string | Some string. |
data | Any | Data for the triggered event. |
eventInit | CustomEventInit | Options for CustomEvent's eventInit argument. |
Examples
Type Definitions
route_ignore() → {boolean}
This:
{just.Router~route}
Returns:
If `true`, the route won't be called.
- Type
- boolean
route_only() → {boolean}
This:
{just.Router~route}
Returns:
If `true`, the route will be called.
- Type
- boolean