dispose method

void dispose()

Removes the popstate window event listener, disconnects the link prefetch observer, and restores browser history scroll restoration.

Must be invoked when the application or router controller is torn down to prevent memory leaks and restore previous browser history settings.

Implementation

void dispose() {
  web.window.removeEventListener('popstate', _popStateListener.toJS);
  if (scrollRestoration && _previousScrollRestoration != null) {
    try {
      web.window.history.scrollRestoration = _previousScrollRestoration!;
    } catch (_) {}
  }
  _intersectionObserver?.disconnect();
  _intersectionObserver = null;

  for (final d in _liveRegionDisposers) {
    try {
      d();
    } catch (_) {}
  }
  _liveRegionDisposers.clear();
  _liveRegion?.remove();
  _liveRegion = null;
}