- Value parameters:
- $popStateEvent
- typically windowEvents.onPopState in Laminar
- deserializeFallback
- receives raw state from History API as input and returns a page to render when the entry in the history can not be deserialized using deserializePage. If you want to perform any logic (such as redirects) in case of this fallback, put it in the renderer (whatever you have responding to router.$currentPage).
- deserializePage
- parse the result of serializePage back into a page. This is called when user navigates using browser back / forward buttons and we load history state If you throw here, deserializeFallback will be called instead.
- initialUrl
- e.g. "http://localhost:8080/page"
- origin
- e.g. "http://localhost:8080", without trailing slash
- owner
- typically unsafeWindowOwner in Laminar (if the router should never die, i.e. it's a whole app router)
- routeFallback
- receives URL as input (either initialUrl or on hashChange event) and returns a page to render when none of the routes match on initial page load. When rendering a fallback page, the URL will stay the same. If you want to perform any logic (such as redirects) in case of this fallback, put it in the renderer (whatever you have responding to router.$currentPage).
- routes
- List of routes that this router can handle. You should only have one router for your app, so put all your routes here. There is no concept of subrouters, this is achieved by a combination of Page type hierarchy and nested rendering signals using the patterns described in README. If none of the routes match the provided URL upon initial page load, routeFallback will be used instead.
- serializePage
- encode page into a History API state record. Return any string here (JSON string is ok) This is called any time you trigger navigation to a page.
- Throws:
- Exception
- when initialUrl is not absolute or does not match origin
- Companion:
- object
Value members
Concrete methods
Note: This does not consider fallback pages unless you provided routes for them.
Note: This does not consider fallback pages unless you provided routes for them.
- Throws:
- Exception
when matching route is not found in router.
Forces router.$currentPage to emit this page without updating the URL or touching the history records.
Forces router.$currentPage to emit this page without updating the URL or touching the history records.
Use this to display a full screen "not found" page when the route matched but is invalid for example because /user/123 refers to a non-existing user, something that you can't know during route matching.
Note, this will update document.title unless the provided page's title is empty. I think updating the title could affect the current record in the history API (not sure, you'd need to check if you care)
Pushes state by creating a new history record. See History API docs on MDN.
Pushes state by creating a new history record. See History API docs on MDN.
Note: This does not consider fallback pages unless you provided routes for them.
Note: This does not consider fallback pages unless you provided routes for them.
- Throws:
- Exception
when matching route is not found in router.
Concrete fields
Note: this can be in an errored state if:
Note: this can be in an errored state if:
- initialUrl does not match origin
- routeFallback was invoked and threw an Exception
- deserializeFallback was invoked and threw an Exception