Skip to content

Commit 2daa9f0

Browse files
MelvinBottruph01
andcommitted
Use useRoute() to scope Home navigation to NOT_FOUND screen only
Instead of always overriding onLinkPress, use useRoute() to detect when NotFoundPage is rendered as the SCREENS.NOT_FOUND screen and only then navigate to HOME. Other callers that render NotFoundPage inline keep their existing onLinkPress behavior. Co-authored-by: truph01 <truph01@users.noreply.github.com>
1 parent d1a16ad commit 2daa9f0

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/pages/ErrorPage/NotFoundPage.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {useRoute} from '@react-navigation/native';
12
import React from 'react';
23
import type {FullPageNotFoundViewProps} from '@components/BlockingViews/FullPageNotFoundView';
34
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
@@ -8,6 +9,7 @@ import Navigation from '@libs/Navigation/Navigation';
89
import useAbsentPageSpan from '@libs/telemetry/useAbsentPageSpan';
910
import ONYXKEYS from '@src/ONYXKEYS';
1011
import ROUTES from '@src/ROUTES';
12+
import SCREENS from '@src/SCREENS';
1113

1214
type NotFoundPageProps = {
1315
onBackButtonPress?: () => void;
@@ -22,6 +24,8 @@ function NotFoundPage({onBackButtonPress = () => Navigation.goBack(), isReportRe
2224
const {isSmallScreenWidth} = useResponsiveLayout();
2325
const topmostReportId = Navigation.getTopmostReportId();
2426
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${topmostReportId}`);
27+
const route = useRoute();
28+
const isNotFoundScreen = route.name === SCREENS.NOT_FOUND;
2529

2630
useAbsentPageSpan();
2731

@@ -32,7 +36,6 @@ function NotFoundPage({onBackButtonPress = () => Navigation.goBack(), isReportRe
3236
>
3337
<FullPageNotFoundView
3438
shouldShow
35-
onLinkPress={() => Navigation.goBack(ROUTES.HOME)}
3639
onBackButtonPress={() => {
3740
if (!isReportRelatedPage || !isSmallScreenWidth) {
3841
onBackButtonPress();
@@ -48,6 +51,7 @@ function NotFoundPage({onBackButtonPress = () => Navigation.goBack(), isReportRe
4851
}}
4952
// eslint-disable-next-line react/jsx-props-no-spreading
5053
{...fullPageNotFoundViewProps}
54+
onLinkPress={isNotFoundScreen ? () => Navigation.goBack(ROUTES.HOME) : fullPageNotFoundViewProps.onLinkPress}
5155
/>
5256
</ScreenWrapper>
5357
);

0 commit comments

Comments
 (0)