Skip to content

@serenity-is/corelib / ClassicRouter

Class: ClassicRouter

Defined in: src/compat/router.ts:107

Legacy hash-based router that maps dialog stack to "/+/" delimited hash segments. Compat shim for the old Router implementation. Listens to hashchange, dialog open/close, and anchor clicks to keep the URL in sync with visible dialogs and to dispatch handleroute events. [DEPRECATED] Use explicit routing or state-driven dialog management. Kept solely for backward compatibility with legacy Serenity pages.

Implements

Constructors

Constructor

new ClassicRouter(): ClassicRouter

Defined in: src/compat/router.ts:574

Returns

ClassicRouter

Properties

enabled

enabled: boolean = true

Defined in: src/compat/router.ts:120

When false, all routing operations become no-ops.

Implementation of

IClassicRouter.enabled


mightBeRouteRegex

mightBeRouteRegex: RegExp

Defined in: src/compat/router.ts:357

Regex used to heuristically detect whether a single hash segment might represent a dialog route (e.g., new, edit/…, !…).

Implementation of

IClassicRouter.mightBeRouteRegex

Methods

destroy()

destroy(): void

Defined in: src/compat/router.ts:593

Removes all event listeners registered by the router and releases resources.

Returns

void

Implementation of

IClassicRouter.destroy


dialog()

dialog(owner, element, dialogHash): void

Defined in: src/compat/router.ts:342

Registers a dialog open for hash tracking. The actual hash mutation is deferred until the dialog is confirmed open.

Parameters

owner

Owner element that triggered the dialog (array-like collections use the first element).

HTMLElement | ArrayLike<HTMLElement>

element

Dialog content element whose data-qroute / data-qprhash attributes will be managed.

HTMLElement | ArrayLike<HTMLElement>

dialogHash

() => string

Factory returning the hash segment for this dialog (e.g., "!a1").

Returns

void

Implementation of

IClassicRouter.dialog


ignoreHashChange()

ignoreHashChange(expiration?): void

Defined in: src/compat/router.ts:499

Temporarily ignores the next hashchange event(s).

Parameters

expiration?

number

Duration in milliseconds to ignore hash changes. Defaults to 1000.

Returns

void

Implementation of

IClassicRouter.ignoreHashChange


navigate(newHash, tryBack?, silent?): void

Defined in: src/compat/router.ts:127

Navigates to a new hash, optionally attempting history.back() when the URL matches the previous one.

Parameters

newHash

string

Hash string with or without leading #. Empty string clears the hash.

tryBack?

boolean

When true, uses history.back() if the target matches ClassicRouter.oldURL.

silent?

boolean

When true, suppresses the subsequent hashchange handling via ignoreHashChange.

Returns

void

Implementation of

IClassicRouter.navigate


registerPageRoute()

registerPageRoute(handler): () => void

Defined in: src/compat/router.ts:211

Registers a handler of the routes of a page that are not of dialogs, e.g. "view/12". They are kept before the routes of the dialogs opened on the page, e.g. "view/12/+/!1", and work besides the handleroute event of the .route-handler element, e.g. of an entity grid.

Parameters

handler

PageRouteHandler

The handler.

Returns

A function that unregisters the handler.

(): void

Returns

void

Implementation of

IClassicRouter.registerPageRoute


replace()

replace(newHash, tryBack?): void

Defined in: src/compat/router.ts:160

Replaces the current hash without adding a history entry (silent navigation).

Parameters

newHash

string

Target hash (with or without #).

tryBack?

boolean

When true, prefers history.back() if applicable.

Returns

void

Implementation of

IClassicRouter.replace


replaceLast()

replaceLast(newHash, tryBack?): void

Defined in: src/compat/router.ts:232

Replaces only the last "/+/" segment of the current hash.

Parameters

newHash

string

Replacement for the last segment; when empty/falsy the last segment is removed.

tryBack?

boolean

When true, prefers history.back() if applicable.

Returns

void

Implementation of

IClassicRouter.replaceLast


resolve()

resolve(newHash?): "disabled" | "skipped" | "shebang" | "missinghandler" | "calledhandler"

Defined in: src/compat/router.ts:360

Resolves the current (or provided) hash by closing/opening dialogs and dispatching handleroute.

Parameters

newHash?

string

Hash to resolve; defaults to window.location.hash when omitted.

Returns

"disabled" | "skipped" | "shebang" | "missinghandler" | "calledhandler"

A status string: "disabled" if the router is disabled, "skipped" if a recent anchor click looks like a non-route hash, "shebang" for ! prefixed routes, "missinghandler" when a handler element cannot be found, or "calledhandler" when a handleroute event was dispatched.

Implementation of

IClassicRouter.resolve