Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cc3ac4f
Previously, users had to manually append fragments
AffanShaikhsurab Dec 5, 2024
7a641b4
extensions.dart file formatted using dart format
AffanShaikhsurab Dec 5, 2024
c740df8
Merge branch 'main' into main
AffanShaikhsurab Dec 7, 2024
2a0cf73
Added the the fragment handling to the
AffanShaikhsurab Dec 10, 2024
851905b
Merge branch 'main' of https://github.com/AffanShaikhsurab/packages
AffanShaikhsurab Dec 10, 2024
29d8f6c
Merge branch 'flutter:main' into main
AffanShaikhsurab Dec 10, 2024
3f3adcb
Merge branch 'main' into main
AffanShaikhsurab Dec 12, 2024
b4c2efc
Merge branch 'main' into main
AffanShaikhsurab Dec 12, 2024
080a38e
Merge branch 'main' into main
AffanShaikhsurab Dec 17, 2024
ebb8cdc
Fix: Include fragment in URI generated by GoRouter
AffanShaikhsurab Dec 17, 2024
b6cfe44
Merge branch 'main' of https://github.com/AffanShaikhsurab/packages
AffanShaikhsurab Dec 17, 2024
62b6027
updated changeLog
AffanShaikhsurab Dec 17, 2024
b948c71
Fix: Implement fragment-based redirection in GoRouter test
AffanShaikhsurab Dec 18, 2024
58a1b12
Merge branch 'main' into main
AffanShaikhsurab Dec 18, 2024
0816efd
dart format
AffanShaikhsurab Dec 18, 2024
32555fc
Merge branch 'main' of https://github.com/AffanShaikhsurab/packages
AffanShaikhsurab Dec 18, 2024
0fee133
added anotation
AffanShaikhsurab Dec 18, 2024
8dec200
Merge branch 'main' into main
AffanShaikhsurab Dec 19, 2024
ea4d752
Merge branch 'main' into main
AffanShaikhsurab Dec 25, 2024
362e23e
Merge branch 'main' into main
AffanShaikhsurab Dec 28, 2024
fcb1b91
Merge branch 'main' into main
AffanShaikhsurab Dec 31, 2024
1bcd8b3
Merge branch 'main' into main
AffanShaikhsurab Jan 3, 2025
0b507b0
Merge branch 'main' into main
AffanShaikhsurab Jan 4, 2025
6651f6c
Refactor: Update `namedLocation` method to include `fragment` parameter
AffanShaikhsurab Jan 11, 2025
1ef08a4
Merge branch 'main' of https://github.com/AffanShaikhsurab/packages
AffanShaikhsurab Jan 11, 2025
b6546a4
Delete packages/go_router/log.txt
AffanShaikhsurab Jan 11, 2025
aed6d08
Merge branch 'main' into main
AffanShaikhsurab Jan 11, 2025
a45bb0d
Merge branch 'main' into main
AffanShaikhsurab Jan 17, 2025
feae635
Merge branch 'main' into main
AffanShaikhsurab Jan 23, 2025
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
Next Next commit
Previously, users had to manually append fragments
hashes to URLs, whichcould lead to potential bugs.
This update introduces a dedicated fragment
parameter, allowing for more seamless and reliable URL navigation.
  • Loading branch information
AffanShaikhsurab committed Dec 5, 2024
commit cc3ac4fdc1db3f2e635e9fe96c7f65a8c8bec43d
4 changes: 4 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 14.7.0

- Adds fragment support to GoRouter, enabling direct specification and automatic handling of fragments in routes.

## 14.6.2

- Replaces deprecated collection method usage.
Expand Down
12 changes: 6 additions & 6 deletions packages/go_router/lib/src/misc/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ extension GoRouterHelper on BuildContext {
Map<String, String> pathParameters = const <String, String>{},
Map<String, dynamic> queryParameters = const <String, dynamic>{},
Object? extra,
String? fragment,
}) =>
GoRouter.of(this).goNamed(
name,
pathParameters: pathParameters,
queryParameters: queryParameters,
extra: extra,
);
GoRouter.of(this).goNamed(name,
pathParameters: pathParameters,
queryParameters: queryParameters,
extra: extra,
fragment: fragment);

/// Push a location onto the page stack.
///
Expand Down
7 changes: 6 additions & 1 deletion packages/go_router/lib/src/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,15 @@ class GoRouter implements RouterConfig<RouteMatchList> {
Map<String, String> pathParameters = const <String, String>{},
Map<String, dynamic> queryParameters = const <String, dynamic>{},
Object? extra,
String? fragment,
}) =>

/// Construct location with optional fragment, using null-safe navigation
go(
namedLocation(name,
pathParameters: pathParameters, queryParameters: queryParameters),
pathParameters: pathParameters,
queryParameters: queryParameters) +
((fragment?.isNotEmpty ?? false) ? '#$fragment' : ''),
extra: extra,
);

Expand Down
6 changes: 5 additions & 1 deletion packages/go_router/lib/src/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,13 @@ class GoRouterState {
String name, {
Map<String, String> pathParameters = const <String, String>{},
Map<String, String> queryParameters = const <String, String>{},
String? fragment,
}) {
// Generate base location using configuration, with optional path and query parameters
// Then conditionally append fragment if it exists and is not empty
return _configuration.namedLocation(name,
pathParameters: pathParameters, queryParameters: queryParameters);
pathParameters: pathParameters, queryParameters: queryParameters) +
((fragment?.isNotEmpty ?? false) ? '#$fragment' : '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add fragment to namedLocation api as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for overlooking that part . Added the the fragment handling to the namedLocation api.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem addressed yet

}

@override
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.6.2
version: 14.7.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
32 changes: 32 additions & 0 deletions packages/go_router/test/go_route_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,38 @@ void main() {
expect(tester.takeException(), isAssertionError);
});

testWidgets('throw if redirect to itself.', (WidgetTester tester) async {
final GoRouter router = await createRouter(
<RouteBase>[
GoRoute(
path: '/',
builder: (_, __) => const Text('home'),
routes: <RouteBase>[
GoRoute(
path: 'route',
name: 'route', // Named route
redirect: (_, __) => '/route',
routes: <RouteBase>[
GoRoute(
path: '1',
builder: (_, __) => const Text('/route/1/2'),
),
],
),
],
),
],
tester,
);
expect(find.text('home'), findsOneWidget);

router.goNamed('route',
fragment: '2'); // Use the name instead of the path
await tester.pumpAndSettle();
// Should redirect to /route/1 without error.
expect(tester.takeException(), isAssertionError);
});

testWidgets('throw if sub route does not conform with parent navigator key',
(WidgetTester tester) async {
final GlobalKey<NavigatorState> key1 = GlobalKey<NavigatorState>();
Expand Down
3 changes: 3 additions & 0 deletions packages/go_router/test/test_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,21 @@ class GoRouterGoNamedSpy extends GoRouter {
Map<String, String>? pathParameters;
Map<String, dynamic>? queryParameters;
Object? extra;
String? fragment;

@override
void goNamed(
String name, {
Map<String, String> pathParameters = const <String, String>{},
Map<String, dynamic> queryParameters = const <String, dynamic>{},
Object? extra,
String? fragment,
}) {
this.name = name;
this.pathParameters = pathParameters;
this.queryParameters = queryParameters;
this.extra = extra;
this.fragment = fragment;
}
}

Expand Down
Loading