[월간코딩] #5 Side Bar 수정

기존 사이드바 만들기 글 보기

문제 발생

원인(As-Is)

index.tsx

<React.StrictMode>
  <ThemeProvider theme={theme}>
    <GlobalStyle />
    <QueryClientProvider client={queryClient}>
      <Provider store={store}>
        <Layout>
          <App />
        </Layout>
      </Provider>
    </QueryClientProvider>
  </ThemeProvider>
</React.StrictMode>

App.tsx

function App() {
  return (
    <Router basename={process.env.PUBLIC_URL}>
      <Routes>
        <Route>
          <Route path='/:id' element={<Memo />} />
          <Route path='/' element={<HomePage />} />
        </Route>
      </Routes>
    </Router>
  );
}

export default App;

Layout.tsx

export default function Layout({ children }: IProps) {
  return (
    <>
      <WrapperRow>
        <SideBar />
        <main>{children}</main>
      </WrapperRow>
    </>
  );
}

수정(To-Be)

index.tsx

<React.StrictMode>
  <ThemeProvider theme={theme}>
    <GlobalStyle />
    <QueryClientProvider client={queryClient}>
      <Provider store={store}>
        <App />
      </Provider>
    </QueryClientProvider>
  </ThemeProvider>
</React.StrictMode>

App.tsx

function App() {
  return (
    <Router basename={process.env.PUBLIC_URL}>
      <Routes>
        <Route element={<Layout />}>
          <Route path='/:id' element={<Memo />} />
          <Route path='/' element={<HomePage />} />
        </Route>
      </Routes>
    </Router>
  );
}

export default App;

Layout.tsx

import { Outlet } from 'react-router-dom';

export default function Layout() {
  return (
    <>
      <WrapperRow>
        <SideBar />
        <Outlet />
      </WrapperRow>
    </>
  );
}