Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

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

default discord avatar
ragnar_lt2 years ago
1

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

  • default discord avatar
    paulpopus2 years ago

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

    https://v5.reactrouter.com/web/api/Hooks/usehistory

    Here you have payload's own hooks

    https://payloadcms.com/docs/admin/hooks#useauth

    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`} />;
      }
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.