Skip to content

Commit dbc87d7

Browse files
committed
Fix 'location is not defined' build warnings
1 parent fc04b85 commit dbc87d7

File tree

1 file changed

+10
-2
lines changed
  • src/app/will-it-cors/components/steps

1 file changed

+10
-2
lines changed

src/app/will-it-cors/components/steps/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use client';
22

3+
import { useEffect } from 'react';
4+
35
import { observer } from 'mobx-react-lite';
46
import { useRouter } from 'next/navigation';
57

@@ -32,8 +34,14 @@ export const Steps = observer(({ currentStep }: { currentStep: WillItCorsSteps }
3234

3335
// If you end up directly on a step without having completed the path this session (e.g.
3436
// if you refresh the page or navigate there directly), we redirect you to the root.
35-
if (currentStep !== 'source-url' && !steps.sourceUrl) {
36-
router.push('/will-it-cors/');
37+
const shouldRedirect = currentStep !== 'source-url' && !steps.sourceUrl;
38+
useEffect(() => {
39+
if (shouldRedirect) {
40+
router.push('/will-it-cors/');
41+
}
42+
}, [shouldRedirect, router]);
43+
44+
if (shouldRedirect) {
3745
return null;
3846
}
3947

0 commit comments

Comments
 (0)