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

Add logic in get active route #33370

Merged
merged 9 commits into from
Jan 2, 2024
Merged
Changes from all commits
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
10 changes: 8 additions & 2 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ function getActiveRoute(): string {
return '';
}

if (currentRoute?.path) {
return currentRoute.path;
}

Comment on lines +98 to +101
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we remove the rest of the logic and only keep this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated

Copy link
Contributor

Choose a reason for hiding this comment

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

@dukenv0307 I just found that currentRoute.path is only available for the first navigated route. We may need to use the rootFromState as a fallback here

Screen.Recording.2023-12-25.at.7.53.50.PM.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your comment, I just updated. Please check again

const routeFromState = getPathFromState(navigationRef.getRootState(), linkingConfig.config);

if (routeFromState) {
Expand All @@ -114,8 +118,10 @@ function getActiveRoute(): string {
* @return is active
*/
function isActiveRoute(routePath: Route): boolean {
// We remove First forward slash from the URL before matching
return getActiveRoute().substring(1) === routePath;
let activeRoute = getActiveRoute();
activeRoute = activeRoute.startsWith('/') ? activeRoute.substring(1) : activeRoute;

return activeRoute === routePath;
}

/**
Expand Down
Loading