@@ -13,7 +13,6 @@ import 'package:js/js.dart';
1313import 'package:meta/meta.dart' ;
1414import 'package:ui/ui.dart' as ui;
1515
16- import '../engine.dart' show registerHotRestartListener;
1716import 'browser_detection.dart' ;
1817import 'navigation/history.dart' ;
1918import 'navigation/js_url_strategy.dart' ;
@@ -50,12 +49,8 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
5049 engineDispatcher.windows[_windowId] = this ;
5150 engineDispatcher.windowConfigurations[_windowId] = const ui.ViewConfiguration ();
5251 if (_isUrlStrategySet) {
53- _browserHistory =
54- MultiEntriesBrowserHistory (urlStrategy: _customUrlStrategy);
52+ _browserHistory = createHistoryForExistingState (_customUrlStrategy);
5553 }
56- registerHotRestartListener (() {
57- window.resetHistory ();
58- });
5954 }
6055
6156 final Object _windowId;
@@ -67,7 +62,7 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
6762 /// button, etc.
6863 BrowserHistory get browserHistory {
6964 return _browserHistory ?? =
70- MultiEntriesBrowserHistory (urlStrategy : _urlStrategyForInitialization);
65+ createHistoryForExistingState ( _urlStrategyForInitialization);
7166 }
7267
7368 UrlStrategy ? get _urlStrategyForInitialization {
@@ -82,32 +77,50 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
8277 _browserHistory; // Must be either SingleEntryBrowserHistory or MultiEntriesBrowserHistory.
8378
8479 Future <void > _useSingleEntryBrowserHistory () async {
80+ // Recreate the browser history mode that's appropriate for the existing
81+ // history state.
82+ //
83+ // If it happens to be a single-entry one, then there's nothing further to do.
84+ //
85+ // But if it's a multi-entry one, it will be torn down below and replaced
86+ // with a single-entry history.
87+ //
88+ // See: https://github.com/flutter/flutter/issues/79241
89+ _browserHistory ?? =
90+ createHistoryForExistingState (_urlStrategyForInitialization);
91+
8592 if (_browserHistory is SingleEntryBrowserHistory ) {
8693 return ;
8794 }
8895
89- final UrlStrategy ? strategy;
90- if (_browserHistory == null ) {
91- strategy = _urlStrategyForInitialization;
92- } else {
93- strategy = _browserHistory? .urlStrategy;
94- await _browserHistory? .tearDown ();
95- }
96+ // At this point, we know that `_browserHistory` is a non-null
97+ // `MultiEntriesBrowserHistory` instance.
98+ final UrlStrategy ? strategy = _browserHistory? .urlStrategy;
99+ await _browserHistory? .tearDown ();
96100 _browserHistory = SingleEntryBrowserHistory (urlStrategy: strategy);
97101 }
98102
99103 Future <void > _useMultiEntryBrowserHistory () async {
104+ // Recreate the browser history mode that's appropriate for the existing
105+ // history state.
106+ //
107+ // If it happens to be a multi-entry one, then there's nothing further to do.
108+ //
109+ // But if it's a single-entry one, it will be torn down below and replaced
110+ // with a multi-entry history.
111+ //
112+ // See: https://github.com/flutter/flutter/issues/79241
113+ _browserHistory ?? =
114+ createHistoryForExistingState (_urlStrategyForInitialization);
115+
100116 if (_browserHistory is MultiEntriesBrowserHistory ) {
101117 return ;
102118 }
103119
104- final UrlStrategy ? strategy;
105- if (_browserHistory == null ) {
106- strategy = _urlStrategyForInitialization;
107- } else {
108- strategy = _browserHistory? .urlStrategy;
109- await _browserHistory? .tearDown ();
110- }
120+ // At this point, we know that `_browserHistory` is a non-null
121+ // `SingleEntryBrowserHistory` instance.
122+ final UrlStrategy ? strategy = _browserHistory? .urlStrategy;
123+ await _browserHistory? .tearDown ();
111124 _browserHistory = MultiEntriesBrowserHistory (urlStrategy: strategy);
112125 }
113126
0 commit comments