0

playing around with protected routes in React Router 4 and wondering whether something that I've been able to get to work is even possible.

<Switch>
    <Route exact path="/" component={LandingPage} />
    <Route path="/sign-in" component={SignIn} />
    <Route exact path="/auth/home" component={Home} />
    <Route exact path="/auth/my-profile" component={UserProfile} />
    <ProtectedRoute path="/auth" />
</Switch>

I have these routes as shown above and I have set up a protected route called /auth

What I want is to use this to protect any and all routes starting with /auth

So in this example both

<Route exact path="/auth/home" component={Home} />
<Route exact path="/auth/my-profile" component={UserProfile} />

Would also be protected routes.

Make sense?

Lee Hitchcock
  • 85
  • 1
  • 10
  • 1
    You could try using a route variable with a function `path="/auth/:page" component={returnComponent()}` which would the required component based on the `page` attribute in `props`. – Andy Nov 30 '18 at 14:05
  • Duplicate: https://stackoverflow.com/a/53024484/7376526 – Matt Carlotta Nov 30 '18 at 17:56

0 Answers0