Skip to content
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

[go _route] fragment parameter added #8232

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

AffanShaikhsurab
Copy link

@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
Author

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

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.
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
2 participants