Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
37be48c
- Adds `GoRouter.goRelative`
ThangVuNguyenViet May 29, 2024
f8061ce
add go_relative example for go_router
ThangVuNguyenViet May 29, 2024
8a77147
add go_relative_test for the example
ThangVuNguyenViet May 29, 2024
61127f3
fix failed test
ThangVuNguyenViet May 29, 2024
687b332
replace goRelative with go('./$path')
ThangVuNguyenViet Jun 19, 2024
cca1454
Commit missing files during merge
ThangVuNguyenViet Jun 19, 2024
975128b
update changelog & version
ThangVuNguyenViet Jun 19, 2024
6d90488
Prevent concatenateUris from adding trailing redundant '?'. Add test …
ThangVuNguyenViet Jun 19, 2024
ccb38f9
Add more `concatenateUris` test. Fix joining params
ThangVuNguyenViet Jun 19, 2024
80d85d6
update example description
ThangVuNguyenViet Jul 10, 2024
a09aa94
Make concatenateUris not merging parameters, only take them from chil…
ThangVuNguyenViet Jul 19, 2024
a174cbe
Add GoRelativeRouteConfig
ThangVuNguyenViet Jul 10, 2024
4cb0334
Add test, examples and example tests for go_router_builder. Temporari…
ThangVuNguyenViet Jul 19, 2024
ceaa318
Add relativeLocation, push, pushReplacement & replace to the Relative…
ThangVuNguyenViet Jul 19, 2024
d3b5355
Merge branch 'flutter-main'
ThangVuNguyenViet Jan 22, 2025
07b4a23
update go_router package dependency
ThangVuNguyenViet Jan 22, 2025
6008b8b
Fix merge issues
ThangVuNguyenViet Jan 22, 2025
d2fbc0e
temporarily add dependency_override
ThangVuNguyenViet Jan 22, 2025
8b5fb4d
change relative route actions to have suffix `Relative`
ThangVuNguyenViet Feb 3, 2025
02c3d7b
Fix example
ThangVuNguyenViet Feb 4, 2025
72c06de
Update go_relative test
ThangVuNguyenViet Feb 6, 2025
edef7a5
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet May 17, 2025
5474303
fix generated file
ThangVuNguyenViet May 17, 2025
dbf7f9d
Fix failed test due to generated files
ThangVuNguyenViet May 17, 2025
37c5490
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet Jun 2, 2025
868a2d5
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet Jun 12, 2025
232dc7d
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet Jul 1, 2025
1d5ad11
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet Jul 9, 2025
f899939
Remove GoRouteData routing methods. Update TypedRelativeGoRoute gener…
ThangVuNguyenViet Jul 9, 2025
92f6cac
remove overrides on other tests
ThangVuNguyenViet Jul 9, 2025
f98505e
make sure relative go route generated code resembles typed go route a…
ThangVuNguyenViet Jul 9, 2025
20fd5d6
update changelog
ThangVuNguyenViet Jul 10, 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
Prev Previous commit
Next Next commit
replace goRelative with go('./$path')
  • Loading branch information
ThangVuNguyenViet committed Jun 19, 2024
commit 687b332e135c3044b73edecad09fcc971acf3fec
4 changes: 2 additions & 2 deletions packages/go_router/example/lib/go_relative.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class HomeScreen extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () => context.goRelative('details'),
onPressed: () => context.go('./details'),
child: const Text('Go to the Details screen'),
),
],
Expand Down Expand Up @@ -93,7 +93,7 @@ class DetailsScreen extends StatelessWidget {
),
TextButton(
onPressed: () {
context.goRelative('settings');
context.go('./settings');
},
child: const Text('Go to the Settings screen'),
),
Expand Down
10 changes: 8 additions & 2 deletions packages/go_router/lib/src/information_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

import 'match.dart';
import 'path_utils.dart';

/// The type of the navigation.
///
Expand Down Expand Up @@ -135,11 +136,16 @@ class GoRouteInformationProvider extends RouteInformationProvider
}

void _setValue(String location, Object state) {
final Uri uri = Uri.parse(location);
Uri uri = Uri.parse(location);

// Check for relative location
if (location.startsWith('./')) {
uri = concatenateUris(_value.uri, uri);
}

final bool shouldNotify =
_valueHasChanged(newLocationUri: uri, newState: state);
_value = RouteInformation(uri: Uri.parse(location), state: state);
_value = RouteInformation(uri: uri, state: state);
if (shouldNotify) {
notifyListeners();
}
Expand Down
7 changes: 0 additions & 7 deletions packages/go_router/lib/src/misc/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ extension GoRouterHelper on BuildContext {
void go(String location, {Object? extra}) =>
GoRouter.of(this).go(location, extra: extra);

/// Navigate relative to a location.
void goRelative(String location, {Object? extra}) =>
GoRouter.of(this).goRelative(
location,
extra: extra,
);

/// Navigate to a named route.
void goNamed(
String name, {
Expand Down
9 changes: 0 additions & 9 deletions packages/go_router/lib/src/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,6 @@ class GoRouter implements RouterConfig<RouteMatchList> {
routeInformationProvider.go(location, extra: extra);
}

/// Navigate to a URI location by appending [relativeLocation] to the current [GoRouterState.matchedLocation] w/ optional query parameters, e.g.
void goRelative(
String relativeLocation, {
Object? extra,
}) {
log('going relative to $relativeLocation');
routeInformationProvider.goRelative(relativeLocation, extra: extra);
}

/// Restore the RouteMatchList
void restore(RouteMatchList matchList) {
log('restoring ${matchList.uri}');
Expand Down
21 changes: 11 additions & 10 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@ void main() {
];

final GoRouter router = await createRouter(routes, tester);
router.goRelative('login');
router.go('./login');
await tester.pumpAndSettle();
expect(find.byType(LoginScreen), findsOneWidget);
});
Expand All @@ -1832,7 +1832,7 @@ void main() {

final GoRouter router = await createRouter(routes, tester);
router.go('/home');
router.goRelative('login');
router.go('./login');
await tester.pumpAndSettle();
expect(find.byType(LoginScreen), findsOneWidget);
});
Expand Down Expand Up @@ -1870,11 +1870,11 @@ void main() {
final GoRouter router =
await createRouter(routes, tester, initialLocation: '/home');

router.goRelative('family/$fid');
router.go('./family/$fid');
await tester.pumpAndSettle();
expect(find.byType(FamilyScreen), findsOneWidget);

router.goRelative('person/$pid');
router.go('./person/$pid');
await tester.pumpAndSettle();
expect(find.byType(PersonScreen), findsOneWidget);
});
Expand Down Expand Up @@ -1911,11 +1911,11 @@ void main() {
final GoRouter router =
await createRouter(routes, tester, initialLocation: '/home');

router.goRelative('family?fid=$fid');
router.go('./family?fid=$fid');
await tester.pumpAndSettle();
expect(find.byType(FamilyScreen), findsOneWidget);

router.goRelative('person?pid=$pid');
router.go('./person?pid=$pid');
await tester.pumpAndSettle();
expect(find.byType(PersonScreen), findsOneWidget);
});
Expand Down Expand Up @@ -1952,7 +1952,7 @@ void main() {
errorBuilder: (BuildContext context, GoRouterState state) =>
TestErrorScreen(state.error!),
);
router.goRelative('family/person/$pid');
router.go('./family/person/$pid');
await tester.pumpAndSettle();
expect(find.byType(TestErrorScreen), findsOneWidget);

Expand Down Expand Up @@ -2023,7 +2023,7 @@ void main() {
final GoRouter router =
await createRouter(routes, tester, initialLocation: '/home');
final String loc = 'page1/${Uri.encodeComponent(param1)}';
router.goRelative(loc);
router.go('./$loc');

await tester.pumpAndSettle();
expect(find.byType(DummyScreen), findsOneWidget);
Expand Down Expand Up @@ -2054,10 +2054,11 @@ void main() {
final GoRouter router =
await createRouter(routes, tester, initialLocation: '/home');

router.goRelative(Uri(
final String loc = Uri(
path: 'page1',
queryParameters: <String, dynamic>{'param1': param1},
).toString());
).toString();
router.go('./$loc');

await tester.pumpAndSettle();
expect(find.byType(DummyScreen), findsOneWidget);
Expand Down