Skip to content

Commit

Permalink
fix(react-router): group index redirect route with steps config (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown authored Nov 29, 2022
1 parent d06dd15 commit 29073ce
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/react-router/src/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ export function Wizard<Values extends object = BaseValues>({ children, initialVa
navigate(wizard.currentStep);
}
});
const step = useRoutes(steps)
const stepsWithRedirect = steps.concat({
index: true,
element: (<Navigate to={String(steps[0]?.name)} replace={true} />),
path: "/"
});
const step = useRoutes(stepsWithRedirect)
const stepFromLocation = location.pathname.split('/').pop();

useEffect(() => {
Expand All @@ -102,12 +107,7 @@ export function Wizard<Values extends object = BaseValues>({ children, initialVa

return (
<WizardContext.Provider value={Object.create(wizard)}>
<>
{step}
</>
<Routes>
<Route index={true} element={<Navigate to={String(steps[0]?.name)} replace={true} />} />
</Routes>
{step}
</WizardContext.Provider>
)
}
Expand Down

0 comments on commit 29073ce

Please sign in to comment.