Skip to content

Latest commit

Β 

History

History
69 lines (54 loc) Β· 1.27 KB

routing.md

File metadata and controls

69 lines (54 loc) Β· 1.27 KB

Routing, layouts, and views

Routing

// Install Router
npm install react-router-dom@6

// Path: @/routes/index.tsx

└── src/
    β”œβ”€β”€ routes/
      β”œβ”€β”€ index.txs  // Routing configuration file

// Config
<BrowserRouter>
  <Routes>
    <Route path="/" element={...}>
	</Routes>
</BrowserRouter>

// Load in view App.tsx
...
	<RoutesPage />
...

Layouts (@/templates/layouts)

  • Layout's useful when project get the different layout, reuse components effective
// Path @/templates/layouts/MainDefault.tsx

// Declare the template layout with children / renderer
const MainLayout = ({ children }) => {
  return (
    <div>
      <Header />
      <Main>{children}</Main>
      <Footer />
    </div>
  );
};

// Calling
import MainDefault from '@/templates/layouts/MainDefault.tsx'
<template>
  <div class="home-layout">
    <MainDefault>
      Main home
    </MainDefault>
  </div>
</template>

Views

  • Container folder may contains all type of feature: Display StateManager TypeSafe SideEffect Style(styled-component) Logic
└── src/
    β”œβ”€β”€ containers/
      β”œβ”€β”€ Login
      β”œβ”€β”€ Home
      β”œβ”€β”€ Global