api

Classes

Router

Router Options

instance: Instance (default: Root Instance)

The instance that this router belongs to.

rootNode: RNode (default: None)

Manually specify the root node. By default the root node from the routes object will be used.

name: string (default: Empty string)

The name of the router. All routers inside an instance must have unique names.

routes: RouteTree (default: none)

The generated routes to be imported into the router.

urlRewrite: UrlRewrite
urlReflector: BaseReflector | AddressReflector | InternalReflector | LocalStorageReflector (default: AddressReflector)

Keeps the internal path synchronized to the browser (AddressReflector) or the local storage (LocalStorageReflector). InternalReflector does not synchronize the internal path to anything.

beforeRouterInit: callback
afterRouterInit: callback
beforeUrlChange: callback

Runs before the route has been changed.

afterUrlChange: callback

Runs after the route has been changed.

transformFragments: (RouteFragment[]) => RouteFragment[]

Manipulate the fragments returned by route.fragments

onDestroy: (Router) => void

Called when the router is destroyed

plugins: Router Options

Plugins share the same options as the router options.

queryHandler: QueryHandler

Synchronizes the query parameters with the path in the address bar.

clickHandler: ClickHandler

Configures which clicks the router listens to.

trailingSlash: never | always | preserve | contextual (default: never)

Whether or not to add a trailing slash to the URL. preserve will keep the trailing slash if it was there, and contextual will add a trailing slash if the URL is a directory, e.g.: /example/index.svelte.


UrlRewrite

toInternal: (url, ctx) => string

Rewrites the external URL (visible in the address bar) before it's passed to the router.

toExternal: (url, ctx) => string

Rewrites the internal URL before it's passed to the router (visible in the address bar).


QueryHandler

parse: (search:string, route:Route) => Object

Parses the query string from the path and returns an object with parameters.

stringify: (params:Object, route:Route) => string

Serializes the parameters and returns a string.


ClickHandler

elem: HTMLElement | () => HTMLElement (default: parent element of router)

The element that will be listened to for clicks.

callback: (event, url) => string | null

Can rewrite the url or ignore the click by returning null.




Need a developer? Hire me!