Skip to content

Commit

Permalink
[web] Freeze window.defaultRouteName (flutter#15565)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdebbar authored and filmil committed Mar 13, 2020
1 parent 404297a commit d7fceba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/web_ui/lib/src/engine/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,14 @@ class EngineWindow extends ui.Window {
/// Simulates clicking the browser's back button.
Future<void> webOnlyBack() => _browserHistory.back();

/// Lazily initialized when the `defaultRouteName` getter is invoked.
///
/// The reason for the lazy initialization is to give enough time for the app to set [locationStrategy]
/// in `lib/src/ui/initialization.dart`.
String _defaultRouteName;

@override
String get defaultRouteName => _browserHistory.currentPath;
String get defaultRouteName => _defaultRouteName ??= _browserHistory.currentPath;

/// Change the strategy to use for handling browser history location.
/// Setting this member will automatically update [_browserHistory].
Expand Down
22 changes: 22 additions & 0 deletions lib/web_ui/test/window_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:test/test.dart';
import 'package:ui/src/engine.dart';

TestLocationStrategy _strategy;
TestLocationStrategy get strategy => _strategy;
set strategy(TestLocationStrategy newStrategy) {
window.locationStrategy = _strategy = newStrategy;
}

void main() {
test('window.defaultRouteName should not change', () {
strategy = TestLocationStrategy.fromEntry(TestHistoryEntry('initial state', null, '/initial'));
expect(window.defaultRouteName, '/initial');

strategy.replaceState(null, null, '/newpath');
expect(window.defaultRouteName, '/initial');
});
}

0 comments on commit d7fceba

Please sign in to comment.