0.2.9 • Published 3 years ago
react-pages-router v0.2.9
Generate routes automatically
Usage
Your App.js/App.ts
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import { Router } from 'react-pages-router';
function App() {
const pages = require.context('./pages', true, /\.(tsx|js)$/);
return (
<BrowserRouter>
<div className='App'>
<Router core={{ Route, Routes }} pages={pages} />
</div>
</BrowserRouter>
);
}
export default App;
Create a pages folder
Folder structure
pages/
- index.js // path = "/"
- contact.js // path = "/contact"
- cms/
- index.js // path = "/cms"
- users.js // path = "/cms/users"
- @layout // layout to be use by routes inside cms folder
- users/
- _id.js // path = "/users/" files with '_' will serves as parameters