提交 09d892b3 编写于 作者: M Mouad Debbar 提交者: Flutter GitHub Bot

[web] Freeze window.defaultRouteName (#15565)

上级 a67d1d24
......@@ -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].
......
// 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');
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册