Skip to content

Commit ba7b3ab

Browse files
authored
fix(route-not-found): Correctly render route not found page when missing trailing slash (#87244)
To reproduce, go to a missing route page without a trailing slash, like: https://sentry.sentry.io/issues/123/abc. You will see a blank page. For whatever reason, the `router.replace` was not doing anything. Switching to `navigate` however, does work as expected.
1 parent 340a65b commit ba7b3ab

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

static/app/views/routeNotFound.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
88
import Sidebar from 'sentry/components/sidebar';
99
import {t} from 'sentry/locale';
1010
import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
11+
import {useNavigate} from 'sentry/utils/useNavigate';
1112
import {useLastKnownRoute} from 'sentry/views/lastKnownRouteContextProvider';
1213

1314
type Props = RouteComponentProps;
1415

15-
function RouteNotFound({router, location}: Props) {
16+
function RouteNotFound({location}: Props) {
17+
const navigate = useNavigate();
1618
const {pathname, search, hash} = location;
1719
const lastKnownRoute = useLastKnownRoute();
1820

@@ -21,7 +23,7 @@ function RouteNotFound({router, location}: Props) {
2123
useLayoutEffect(() => {
2224
// Attempt to fix trailing slashes first
2325
if (isMissingSlash) {
24-
router.replace(`${pathname}/${search}${hash}`);
26+
navigate(`${pathname}/${search}${hash}`, {replace: true});
2527
return;
2628
}
2729

@@ -32,7 +34,7 @@ function RouteNotFound({router, location}: Props) {
3234
scope.setTag('lastKnownRoute', lastKnownRoute);
3335
Sentry.captureException(new Error('Route not found'));
3436
});
35-
}, [pathname, search, hash, isMissingSlash, router, lastKnownRoute]);
37+
}, [pathname, search, hash, isMissingSlash, lastKnownRoute, navigate]);
3638

3739
if (isMissingSlash) {
3840
return null;

0 commit comments

Comments
 (0)