Skip to content

[go _route] fragment parameter added #8232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jan 23, 2025
Merged

Conversation

AffanShaikhsurab
Copy link
Contributor

@AffanShaikhsurab AffanShaikhsurab commented Dec 5, 2024

Description of Change

This PR addresses the need for fragments/hashes to be treated as first-party parameters within the go_router package, as highlighted in issue #150155. Previously, users had to manually append the fragment to the URL, which could lead to potential bugs. With this update, the fragment is now a dedicated parameter, allowing for a more seamless and bug-free integration.

Before:

final location = context.namedLocation('some_route'); // const nested records
// Manually adding the fragment, hoping there aren't any weird bugs surrounding it
context.replace('$location#https://a.url/that?i=mightuse');

After:

// Directly passing the fragment as a parameter
context.goNamed("details", fragment: 'https://a.url/that?i=mightuse');

// or

final location = GoRouterState.of(context).namedLocation(
  'details',
  fragment: 'section3',
);
context.go(location);

// or 

final location = context.namedLocation(
 'details',
 fragment: 'section3',
);
context.go(location);

Issues Fixed

This PR resolves issue #150155.


Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

hashes to URLs, whichcould lead to potential bugs.
This update introduces a dedicated fragment
parameter, allowing for more seamless and reliable URL navigation.
@AffanShaikhsurab AffanShaikhsurab changed the title Previously, users had to manually append fragments [go _route] fragment parameter added Dec 5, 2024
to remove the  Linux repo_checks error.
@chunhtai chunhtai requested a review from hannah-hyj December 5, 2024 22:40
@AffanShaikhsurab
Copy link
Contributor Author

@chunhtai @hannah-hyj Can you please tell me what improvements I should make?

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

AffanShaikhsurab and others added 3 commits December 10, 2024 07:32
namedLocation api

final location = context.namedLocation(
 'details',
 fragment: 'section3',
);
context.go(location);
AffanShaikhsurab and others added 5 commits December 18, 2024 09:36
- Added logic to redirect to '/route/1' if the fragment is '1' in the '/route' route.
- Updated test to verify correct redirection and ensure no infinite redirects occur.
- Ensured proper navigation based on fragment values using router.goNamed().
- Added assertions to check for expected behavior and prevent exceptions during navigation.
@AffanShaikhsurab
Copy link
Contributor Author

@chunhtai Could you please tell me what needs to be fixed?

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

AffanShaikhsurab and others added 4 commits January 11, 2025 13:14
- Modified `namedLocation` method to pass `fragment` directly to `_configuration.namedLocation`.
- Simplifies handling of the fragment by removing manual concatenation logic.
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -1146,3 +1150,4 @@
## 0.1.0

- squatting on the package name (I'm not too proud to admit it)

Copy link
Contributor

Choose a reason for hiding this comment

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

additional line?

@@ -7,6 +11,7 @@
- Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
- Updates readme.


Copy link
Contributor

Choose a reason for hiding this comment

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

additional line?

Copy link
Member

@hannah-hyj hannah-hyj left a comment

Choose a reason for hiding this comment

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

LGTM

@hannah-hyj hannah-hyj merged commit ac08525 into flutter:main Jan 23, 2025
77 checks passed
@chunhtai
Copy link
Contributor

@hannah-hyj I think there are still some minor formatting issue of changelog

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 27, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Jan 27, 2025
flutter/packages@3d3ab7b...258f6dc

2025-01-24 adsonpleal@gmail.com [shared_preferences] Add shared
preferences devtool (flutter/packages#8494)
2025-01-24 tarrinneal@gmail.com [shared_preferences] update List<String>
encode/decode (flutter/packages#8335)
2025-01-24 engine-flutter-autoroll@skia.org Manual roll Flutter from
c1561a4 to c1ffaa9 (21 revisions) (flutter/packages#8498)
2025-01-24 stuartmorgan@google.com [ios_platform_images] Switch to
`loadImage` (flutter/packages#8216)
2025-01-24 mchudy@users.noreply.github.com [camera] Remove OCMock from
CameraExposureTests and CameraFocusTests (flutter/packages#8351)
2025-01-24 tarrinneal@gmail.com [shared_preferences] Tool for migrating
from legacy shared_preferences to shared_preferences_async
(flutter/packages#8229)
2025-01-23 stuartmorgan@google.com Revert "[shared_preferences] Add
shared preferences devtool" (flutter/packages#8493)
2025-01-23 20254485+kaboc@users.noreply.github.com [go_router] Fix
return type of current state getter to be non-nullable
(flutter/packages#8173)
2025-01-23 engine-flutter-autoroll@skia.org Manual roll Flutter from
b2f515f to c1561a4 (18 revisions) (flutter/packages#8491)
2025-01-23 tarrinneal@gmail.com [pigeon] fixes event channel dart
instance name usage and adds test (flutter/packages#8483)
2025-01-23 51104750+AffanShaikhsurab@users.noreply.github.com [go
_route] fragment parameter added (flutter/packages#8232)
2025-01-23 mchudy@users.noreply.github.com [in_app_purchase] Update
in_app_purchase_android version in in_app_purchase
(flutter/packages#8463)
2025-01-23 stuartmorgan@google.com [image_picker] Reference alternate
macOS implementations (flutter/packages#8487)
2025-01-23 32538273+ValentinVignal@users.noreply.github.com [rfw]
Activate leak testing (flutter/packages#8370)
2025-01-23 32538273+ValentinVignal@users.noreply.github.com
[video_player] Activate leak testing (flutter/packages#8379)
2025-01-23 engine-flutter-autoroll@skia.org Manual roll Flutter from
b9e86a5 to b2f515f (42 revisions) (flutter/packages#8482)
2025-01-23 olli.helenius@codemate.com [camera] Add API support query for
image streaming (app-facing) (flutter/packages#8422)
2025-01-23 engine-flutter-autoroll@skia.org Manual roll Flutter from
b9e86a5 to eb6af3d (13 revisions) (flutter/packages#8473)
2025-01-23 adsonpleal@gmail.com [shared_preferences] Add shared
preferences devtool (flutter/packages#8322)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
androidseb pushed a commit to androidseb/packages that referenced this pull request Jun 8, 2025
### Description of Change

This PR addresses the need for fragments/hashes to be treated as
first-party parameters within the `go_router` package, as highlighted in
[issue #150155](flutter/flutter#150155).
Previously, users had to manually append the fragment to the URL, which
could lead to potential bugs. With this update, the `fragment` is now a
dedicated parameter, allowing for a more seamless and bug-free
integration.

#### Before:

```dart
final location = context.namedLocation('some_route'); // const nested records
// Manually adding the fragment, hoping there aren't any weird bugs surrounding it
context.replace('$location#https://a.url/that?i=mightuse');
```

#### After:

```dart
// Directly passing the fragment as a parameter
context.goNamed("details", fragment: 'https://a.url/that?i=mightuse');

// or

final location = GoRouterState.of(context).namedLocation(
  'details',
  fragment: 'section3',
);
context.go(location);

// or 

final location = context.namedLocation(
 'details',
 fragment: 'section3',
);
context.go(location);
```

### Issues Fixed

This PR resolves [issue
#150155](flutter/flutter#150155).

---

## Pre-launch Checklist

- [✔️ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [✔️ ] I read the [Tree Hygiene] page, which explains my
responsibilities.
- [✔️ ] I read and followed the [relevant style guides] and ran the
auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages
repo does use `dart format`.)
- [x] I signed the [CLA].
- [✔️ ] The title of the PR starts with the name of the package
surrounded by square brackets, e.g. `[shared_preferences]`
- [✔️ ] I [linked to at least one issue that this PR fixes] in the
description above.
- [✔️ ] I updated `pubspec.yaml` with an appropriate new version
according to the [pub versioning philosophy], or this PR is [exempt from
version changes].
- [ ✔️] I updated `CHANGELOG.md` to add a description of the change,
[following repository CHANGELOG style], or this PR is [exempt from
CHANGELOG changes].
- [✔️ ] I updated/added relevant documentation (doc comments with
`///`).
- [ ✔️] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ✔️] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md
[relevant style guides]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style
[CLA]: https://cla.developers.google.com/
[Discord]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
[linked to at least one issue that this PR fixes]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview
[pub versioning philosophy]: https://dart.dev/tools/pub/versioning
[exempt from version changes]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version
[following repository CHANGELOG style]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style
[exempt from CHANGELOG changes]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog
[test-exempt]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
FMorschel pushed a commit to FMorschel/packages that referenced this pull request Jun 9, 2025
### Description of Change

This PR addresses the need for fragments/hashes to be treated as
first-party parameters within the `go_router` package, as highlighted in
[issue #150155](flutter/flutter#150155).
Previously, users had to manually append the fragment to the URL, which
could lead to potential bugs. With this update, the `fragment` is now a
dedicated parameter, allowing for a more seamless and bug-free
integration.

#### Before:

```dart
final location = context.namedLocation('some_route'); // const nested records
// Manually adding the fragment, hoping there aren't any weird bugs surrounding it
context.replace('$location#https://a.url/that?i=mightuse');
```

#### After:

```dart
// Directly passing the fragment as a parameter
context.goNamed("details", fragment: 'https://a.url/that?i=mightuse');

// or

final location = GoRouterState.of(context).namedLocation(
  'details',
  fragment: 'section3',
);
context.go(location);

// or 

final location = context.namedLocation(
 'details',
 fragment: 'section3',
);
context.go(location);
```

### Issues Fixed

This PR resolves [issue
#150155](flutter/flutter#150155).

---

## Pre-launch Checklist

- [✔️ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [✔️ ] I read the [Tree Hygiene] page, which explains my
responsibilities.
- [✔️ ] I read and followed the [relevant style guides] and ran the
auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages
repo does use `dart format`.)
- [x] I signed the [CLA].
- [✔️ ] The title of the PR starts with the name of the package
surrounded by square brackets, e.g. `[shared_preferences]`
- [✔️ ] I [linked to at least one issue that this PR fixes] in the
description above.
- [✔️ ] I updated `pubspec.yaml` with an appropriate new version
according to the [pub versioning philosophy], or this PR is [exempt from
version changes].
- [ ✔️] I updated `CHANGELOG.md` to add a description of the change,
[following repository CHANGELOG style], or this PR is [exempt from
CHANGELOG changes].
- [✔️ ] I updated/added relevant documentation (doc comments with
`///`).
- [ ✔️] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ✔️] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md
[relevant style guides]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style
[CLA]: https://cla.developers.google.com/
[Discord]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
[linked to at least one issue that this PR fixes]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview
[pub versioning philosophy]: https://dart.dev/tools/pub/versioning
[exempt from version changes]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version
[following repository CHANGELOG style]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style
[exempt from CHANGELOG changes]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog
[test-exempt]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[go_router] make fragments/hash a first-party parameter like query and path
3 participants