Skip to main content

Redirect on mount

The Redirect component can be used to replace the current history entry as soon as it is mounted. The history entry is always replaced (not pushed) to avoid blocking back navigation.

const App = () => {
return (
<Route path={'/go-home'}>
<Redirect href="/" />
</Route>
);
};

It also accepts an optional state property to set history state data.

const App = () => {
return (
<Route path={'/go-home'}>
<Redirect href="/" state={{ key: 'value' }} />
</Route>
);
};