A
A
Alexander Kondakov2019-10-17 10:44:27
React
Alexander Kondakov, 2019-10-17 10:44:27

How to make a nested Route in React?

Good morning. I hope I phrased the question correctly. How to correctly implement routing for the admin panel from the point of view of the application architecture.
We have an entry point to the admin panel.

<Route exact path='/admin' render={(props) => (<Admin {...props} data={state}/>)}/>

Everything is great, it works, but now how to make your own routing in the Admin component. After all, the admin panel has its own sitebar, I wanted only the content in the main tag to change.
<div className="wrapper">
    <h1 className="h1">Админка</h1>
    <div className="d-flex mt-40">
      <aside className={style.asideMenu}>
      <AdminMenu path={match.path} menu={data.adminSidebar}/>
      </aside>
    <main>
      <Switch>
      <Route path="/articles" component={AdminPageArticle} />
                        <Route path="/posts" component={AdminPagePosts} />
                        <Route path="/users" component={AdminPageUsers} />
      </Switch>
    </main>
    </div>
    </div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
grinat, 2019-10-17
@grinat

Something like this is possible:

<Route path="/im/">
            <Topbar/> <---- тыц
            <Switch>
              <Route path="/im/dialogs" component={Dialogs}/>
              <Route path="/im/dialog/:id" component={Dialog}/>
            </Switch>
          </Route>

P
Pavel Didenko, 2019-10-17
@Dasslier

What's the problem with using paths that match your needs?
/admin/articles
/admin/posts
/admin/users

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question