diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..caadecd --- /dev/null +++ b/index.d.ts @@ -0,0 +1,23 @@ +import { RiotComponentWrapper, RiotComponent } from 'riot' +import { URLWithParams } from 'rawth' + +export * from 'rawth' +export type Route = RiotComponentWrapper< + RiotComponent<{ + path: string + 'on-before-mount'?: (path: URLWithParams) => void + 'on-mounted'?: (path: URLWithParams) => void + 'on-before-unmount'?: (path: URLWithParams) => void + 'on-unmounted'?: (path: URLWithParams) => void + }> +> +export type Router = RiotComponentWrapper< + RiotComponent<{ + base?: string + 'initial-route'?: string + 'on-started'?: (route: string) => void + }> +> +export declare function getCurrentRoute(): string +export declare function initDomListeners(): void +export declare function setBase(base: string): void diff --git a/package.json b/package.json index 643c099..18103d6 100644 --- a/package.json +++ b/package.json @@ -78,13 +78,13 @@ "sinon-chai": "^3.7.0" }, "peerDependency": { - "riot": "^6.0.0 || ^7.0.0" + "riot": "^6.0.0 || ^7.0.0 || ^9.0.0" }, "dependencies": { "@riotjs/util": "^2.2.3", "bianco.attr": "^1.1.1", - "bianco.query": "^1.1.4", "bianco.events": "^1.1.1", + "bianco.query": "^1.1.4", "cumpa": "^2.0.1", "rawth": "^3.0.0" } diff --git a/src/components/route-hoc.js b/src/components/route-hoc.js index 55badb6..e157ab2 100644 --- a/src/components/route-hoc.js +++ b/src/components/route-hoc.js @@ -119,7 +119,7 @@ export const routeHoc = ({ slots, attributes }) => { this.slot.unmount({}, this.context, true) this.clearDOM(false) this.state.route = null - this.callLifecycleProperty('onUnmounted', this.state.route) + this.callLifecycleProperty('onUnmounted', route) }, onRoute(route) { this.state.route = route diff --git a/src/set-base.js b/src/set-base.js index 10d220e..ac720ba 100644 --- a/src/set-base.js +++ b/src/set-base.js @@ -1,5 +1,5 @@ import { HASH, SLASH } from './constants.js' -import { defaults } from 'rawth' +import { configure } from 'rawth' import { getWindow } from './util.js' export const normalizeInitialSlash = (str) => @@ -33,5 +33,5 @@ export const normalizeBase = (base) => { } export default function setBase(base) { - defaults.base = normalizeBase(base) + configure({ base: normalizeBase(base) }) }