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
Merge branch 'main' into go_router_current_state
  • Loading branch information
chunhtai authored Oct 31, 2024
commit ca30f198dd1ec98b4435dd33926bbddfc44c7091
14 changes: 13 additions & 1 deletion packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
## 14.4.0

- Adds current state getter on `GoRouter` that returns the current `GoRouterState`.

## 14.3.0

- Adds missing implementation for the routerNeglect parameter in GoRouter.

## 14.2.9

- Relaxes route path requirements. Both root and child routes can now start with or without '/'.

## 14.2.8

- Add current state getter on `GoRouter` that returns the current `GoRouterState`.
- Updated custom_stateful_shell_route example to better support swiping in TabView as well as demonstration of the use of PageView.

## 14.2.7

Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: go_router
description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more
version: 14.2.8
version: 14.4.0
repository: https://github.com/flutter/packages/tree/main/packages/go_router
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22

Expand Down
88 changes: 88 additions & 0 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5545,6 +5545,94 @@ void main() {
expect(state?.name, 'tulips');
expect(state?.fullPath, '/tulips');
});

testWidgets('should allow route paths without leading /',
(WidgetTester tester) async {
final List<GoRoute> routes = <GoRoute>[
GoRoute(
path: '/', // root cannot be empty (existing assert)
builder: (BuildContext context, GoRouterState state) =>
const HomeScreen(),
routes: <RouteBase>[
GoRoute(
path: 'child-route',
builder: (BuildContext context, GoRouterState state) =>
const Text('/child-route'),
routes: <RouteBase>[
GoRoute(
path: 'grand-child-route',
builder: (BuildContext context, GoRouterState state) =>
const Text('/grand-child-route'),
),
GoRoute(
path: 'redirected-grand-child-route',
redirect: (BuildContext context, GoRouterState state) =>
'/child-route',
),
],
)
],
),
];

final GoRouter router = await createRouter(routes, tester,
initialLocation: '/child-route/grand-child-route');
RouteMatchList matches = router.routerDelegate.currentConfiguration;
expect(matches.matches, hasLength(3));
expect(matches.uri.toString(), '/child-route/grand-child-route');
expect(find.text('/grand-child-route'), findsOneWidget);

router.go('/child-route/redirected-grand-child-route');
await tester.pumpAndSettle();
matches = router.routerDelegate.currentConfiguration;
expect(matches.matches, hasLength(2));
expect(matches.uri.toString(), '/child-route');
expect(find.text('/child-route'), findsOneWidget);
});

testWidgets('should allow route paths with leading /',
(WidgetTester tester) async {
final List<GoRoute> routes = <GoRoute>[
GoRoute(
path: '/',
builder: (BuildContext context, GoRouterState state) =>
const HomeScreen(),
routes: <RouteBase>[
GoRoute(
path: '/child-route',
builder: (BuildContext context, GoRouterState state) =>
const Text('/child-route'),
routes: <RouteBase>[
GoRoute(
path: '/grand-child-route',
builder: (BuildContext context, GoRouterState state) =>
const Text('/grand-child-route'),
),
GoRoute(
path: '/redirected-grand-child-route',
redirect: (BuildContext context, GoRouterState state) =>
'/child-route',
),
],
)
],
),
];

final GoRouter router = await createRouter(routes, tester,
initialLocation: '/child-route/grand-child-route');
RouteMatchList matches = router.routerDelegate.currentConfiguration;
expect(matches.matches, hasLength(3));
expect(matches.uri.toString(), '/child-route/grand-child-route');
expect(find.text('/grand-child-route'), findsOneWidget);

router.go('/child-route/redirected-grand-child-route');
await tester.pumpAndSettle();
matches = router.routerDelegate.currentConfiguration;
expect(matches.matches, hasLength(2));
expect(matches.uri.toString(), '/child-route');
expect(find.text('/child-route'), findsOneWidget);
});
}

class TestInheritedNotifier extends InheritedNotifier<ValueNotifier<String>> {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.