Layer Routing
Introduction
Layer routing in @esmx/router provides a mechanism for creating isolated routing contexts that overlay the main application. Layers are commonly used for modal dialogs, wizards, or any UI that needs its own navigation stack while visually overlaying the main content.
Type Definitions
RouteLayerOptions
- Type Definition:
Configuration options for layer creation:
zIndex
- Type:
number
Custom z-index value for the layer. If not set, uses the base z-index (10000) plus an auto-incremented value.
keepAlive
- Type:
'exact' | 'include' | RouteVerifyHook - Default:
'exact'
Controls when the layer remains open during navigation:
'exact': Keep layer alive only when navigating to the exact initial path (default)'include': Keep layer alive when navigating to paths that start with the initial pathfunction: Custom logic returningtrueto keep alive,falseto close
autoPush
- Type:
boolean - Default:
true
Whether to automatically push the layer's exit route to the parent router when the layer closes due to a navigation push.
push
- Type:
boolean - Default:
true
Whether to record a history entry for the layer opening. When true, pressing the browser back button will close the layer.
routerOptions
- Type:
RouterLayerOptions
Additional router options for the layer's internal router instance. Merged with the parent router's configuration.
RouterLayerOptions
- Type Definition:
Router options for layer creation. Same as RouterOptions but excludes handler functions and the layer flag which are managed internally.
RouteLayerResult
- Type Definition:
Result returned when a layer closes:
close: Layer was closed viarouter.closeLayer()without data, or by navigating backpush: Layer was closed because navigation exited the layer's scopesuccess: Layer was closed viarouter.closeLayer(data)with data
Methods
router.createLayer()
- Parameters:
toInput: RouteLocationInput— Target route for the layer
- Returns:
Promise<{ promise: Promise<RouteLayerResult>; router: Router }>
Creates a layer routing instance. Returns both the layer's router and a promise that resolves when the layer closes.
router.pushLayer()
- Parameters:
toInput: RouteLocationInput— Target route location
- Returns:
Promise<RouteLayerResult>
Shorthand for creating a layer and waiting for its result. Navigates to the route as a layer.
router.closeLayer()
- Parameters:
data?: any— Optional data to return to the parent
- Returns:
void
Closes the current layer. Only effective when the router is a layer instance (router.isLayer === true).
Layer Lifecycle
- Creation:
createLayer()orpushLayer()creates a new Router instance inmemorymode - Mounting: The layer's root element is appended to the
document.bodywith overlay styling - Navigation: The layer has its own isolated navigation stack
- Closing: The layer closes when:
closeLayer()is called- The user navigates back with no history left
- Navigation exits the layer's
keepAlivescope
- Cleanup:
destroy()is called automatically, removing the DOM element and cleaning up resources