Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix comments
  • Loading branch information
cedvdb committed Sep 24, 2024
commit 04d076ada633404a33a4b56ec95b3e112379873e
6 changes: 4 additions & 2 deletions packages/go_router/lib/src/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList>
}());
}

/// The current [GoRouterState]
GoRouterState? get currentState => currentConfiguration.last
/// This top [GoRouterState].
/// This returns the state of the route that was last used in
/// either [GoRouter.go] or [GoRouter.push].
GoRouterState? get state => currentConfiguration.last
.buildState(_configuration, currentConfiguration);

/// For use by the Router architecture as part of the RouterDelegate.
Expand Down
6 changes: 4 additions & 2 deletions packages/go_router/lib/src/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,10 @@ class GoRouter implements RouterConfig<RouteMatchList> {
}());
}

/// The current [GoRouterState].
GoRouterState? get currentState => routerDelegate.currentState;
/// This top [GoRouterState].
/// This returns the state of the route that was last used in
/// either [GoRouter.go] or [GoRouter.push].
GoRouterState? get state => routerDelegate.state;

/// Whether the imperative API affects browser URL bar.
///
Expand Down
17 changes: 12 additions & 5 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5539,31 +5539,38 @@ void main() {
final GoRouter router = await createRouter(routes, tester);
await tester.pumpAndSettle();

GoRouterState? state = router.currentState;
GoRouterState? state = router.state;
expect(state?.name, 'home');
expect(state?.fullPath, '/');

router.go('/books');
await tester.pumpAndSettle();
state = router.currentState;
state = router.state;
expect(state?.name, 'books');
expect(state?.fullPath, '/books');

router.push('/boats');
await tester.pumpAndSettle();
state = router.currentState;
state = router.state;
expect(state?.name, 'boats');
expect(state?.fullPath, '/boats');

router.pop();
await tester.pumpAndSettle();
state = router.currentState;
state = router.state;
expect(state?.name, 'books');
expect(state?.fullPath, '/books');

router.go('/tulips');
await tester.pumpAndSettle();
state = router.currentState;
state = router.state;
expect(state?.name, 'tulips');
expect(state?.fullPath, '/tulips');

router.go('/books');
router.push('/tulips');
await tester.pumpAndSettle();
state = router.state;
expect(state?.name, 'tulips');
expect(state?.fullPath, '/tulips');
});
Expand Down