Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

Create <Media query={ ... } /> component #12

Open
mrtnzlml opened this issue Aug 19, 2018 · 0 comments
Open

Create <Media query={ ... } /> component #12

mrtnzlml opened this issue Aug 19, 2018 · 0 comments

Comments

@mrtnzlml
Copy link
Member

See: https://reacttraining.com/react-router/core/guides/philosophy/responsive-routes

const App = () => (
  <AppLayout>
    <Route path="/invoices" component={Invoices}/>
  </AppLayout>
)

const Invoices = () => (
  <Layout>

    {/* always show the nav */}
    <InvoicesNav/>

    <Media query={PRETTY_SMALL}>
      {screenIsSmall => screenIsSmall
        // small screen has no redirect
        ? <Switch>
            <Route exact path="/invoices/dashboard" component={Dashboard}/>
            <Route path="/invoices/:id" component={Invoice}/>
          </Switch>
        // large screen does!
        : <Switch>
            <Route exact path="/invoices/dashboard" component={Dashboard}/>
            <Route path="/invoices/:id" component={Invoice}/>
            <Redirect from="/invoices" to="/invoices/dashboard"/>
          </Switch>
      }
    </Media>
  </Layout>
)
@mrtnzlml mrtnzlml self-assigned this Aug 26, 2018
@mrtnzlml mrtnzlml removed their assignment Sep 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant