Skip to content

CacheRoute inside another Function Component #55

@chitgoks

Description

@chitgoks

I commend this library because it saves a lot of new users from having to be forced to learn redux just to cater to this router issue.

My issue is because I created a functional component called ProtectedRoute where it returns the CacheRoute or a redirect if the user is not authenticated.

I place the ProtectedRoute tag in the CacheSwitch but it does not work. any idea what could be wrong with this code? Thank you

const ProtectedRoute = (props) => {
    return localStorage.getItem('user') !== null
        ? <CacheRoute {...props} />
        : <Redirect to="/login"/>;
};

export default ProtectedRoute;

And this is the cache switch

<CacheSwitch>
              <ProtectedRoute component={MyComponent} path="/" exact/>
</CacheSwitch>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions