How to redirect without reloading the page using custom components and custom routes

default discord avatar
5 months ago

I need to move between these paths and get information from the url using custom React components

  • default discord avatar
    5 months ago

    Payload uses the react-router directly, you should be able to use this hook

    Here you have payload's own hooks

    if you have custom components on routes you're responsible for handling the redirect based on auth

    Here's an example though

    import { Redirect } from "react-router-dom";
    // ... inside component
    if (!user || (user && !canAccessAdmin)) {
        return <Redirect to={`${adminRoute}/unauthorized`} />;
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.