Location and Route Reuse
The in-memory history classes that let Angular Router run without a URL bar, and an opt-in strategy that keeps route views alive. import { LynxRouteReuseStrategy, LynxLocationStrategy, LynxPlatformLocation } from '@blotch/angular-lynx';
Usage
provideRouter() installs LynxLocationStrategy and LynxPlatformLocation for you. Angular's Location service calls them, so you rarely call them yourself.
LynxRouteReuseStrategy is opt-in. Provide it after provideRouter():
API
LynxRouteReuseStrategy
Keeps each route's component alive when you navigate away, and reattaches it when you come back. provideRouter() doesn't install it.
ngOnDestroydoesn't run when you leave a route, and component state survives.- Views are stored by route path, so
/user/1and/user/2share one stored view. - Nothing is ever evicted: every route you visit stays in memory.
- It doesn't save native elements. A reattached route rebuilds its elements, as a new one creates them. See Renderer internals.
LynxLocationStrategy
A LocationStrategy that keeps a history stack in memory, starting at /. Angular's Location service calls it, so you rarely call it yourself.
canGoBack: a replaced entry doesn't count. The Android back button goes back while it'strue.historyIndex:LynxStackOutletkeeps each screen's, so its swipe goes back to the entry before the screen's.historyGo(): a move past either end does nothing.
LynxPlatformLocation
A PlatformLocation with its own in-memory history, since Lynx has no browser history or window.location. Its URLs are the router's paths, with no origin, so href puts lynx://app in front of them.
Related
- Routing:
provideRouter(), which installs the location classes. - Routing and navigation: when to keep route views alive.
- Renderer internals: what a reattached route rebuilds.
- Angular
RouteReuseStrategy
