Router: Use React.Fragment inside Router component?

Created on 22 Oct 2018  路  3Comments  路  Source: reach/router

Hi. When I use React.Fragment inside Router, it gave me an error. I wonder if that's the intended behavior or if it's some sort of a bug?

Here is my use case:

{isAuthed ? (
    <React.Fragment>
        <Redirect from="/sign-in" to="/" />
        <Redirect from="/sign-up" to="/" />
    <React.Fragment>
) : (
    <React.Fragment>
        <SignInPage path="/sign-in" />
        <SignUpPage path="/sign-up" />
    <React.Fragment>
)}

Here is the error:
screen shot 2018-10-22 at 1 58 05 am

Most helpful comment

We ran into this issue too, but with a slightly different use case. We have routes we want to expose based on what type of user is using the app. Ie. if it's a client, they have the cilent routes, if it's an internal user they have the internal user routes. That way routes they aren't allowed to acceess don't even get exposed (and the code will never get downloaded via lazy loading).

Ie.

<Router>
  <Login path="/login">
  <Register path="/register">
  {isClient  ? 
     <>
       <ClientUI path="/client" />
      {/* ClientAdminUI is separate for lazy loading purposes; same user type, different route */}
      <ClientAdminUI path="/admin" />
    </> : null}
    {isInternalEmployee ? <InternalEmployeeUI path="/internal" />}
</Router>

All 3 comments

+1, same error with the same usercase

If it fits your broader use case, I would suggest returning different Routers per auth state - not just routes.

We ran into this issue too, but with a slightly different use case. We have routes we want to expose based on what type of user is using the app. Ie. if it's a client, they have the cilent routes, if it's an internal user they have the internal user routes. That way routes they aren't allowed to acceess don't even get exposed (and the code will never get downloaded via lazy loading).

Ie.

<Router>
  <Login path="/login">
  <Register path="/register">
  {isClient  ? 
     <>
       <ClientUI path="/client" />
      {/* ClientAdminUI is separate for lazy loading purposes; same user type, different route */}
      <ClientAdminUI path="/admin" />
    </> : null}
    {isInternalEmployee ? <InternalEmployeeUI path="/internal" />}
</Router>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

EJIqpEP picture EJIqpEP  路  4Comments

thupi picture thupi  路  4Comments

alexandernanberg picture alexandernanberg  路  3Comments

ricardobrandao picture ricardobrandao  路  5Comments

sseppola picture sseppola  路  4Comments