Skip to content

Commit 07ce878

Browse files
ROUTING
1 parent d41a2fb commit 07ce878

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

react.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,4 +1365,54 @@ const FunctionalComponent = () => {
13651365
return (
13661366
<p>{data}</p>
13671367
)
1368-
}
1368+
}
1369+
1370+
1371+
1372+
// ROUTING !!very much different in V6
1373+
1374+
// install react-router-dom (yarn or npm)
1375+
1376+
// V6 basics
1377+
import { BrowserRouter, Routes, Route } from "react-router-dom";
1378+
const FunctionalComponent = () => {
1379+
return (
1380+
<BrowserRouter>
1381+
<Routes>
1382+
<Route path="/" element={<App />}>
1383+
<Route index element={<Home />} />
1384+
<Route path="blog">
1385+
<Route path=":id" element={<BlogPost />} />
1386+
<Route index element={<Blog />} />
1387+
</Route>
1388+
<Route path="about" element={<About />} />
1389+
</Route>
1390+
<Route path="*" element={<PageNotFound />} />
1391+
</Routes>
1392+
</BrowserRouter>,
1393+
)
1394+
}
1395+
1396+
// V5 basics
1397+
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
1398+
// import different page components
1399+
const FunctionalComponent = () => {
1400+
return (
1401+
<Router>
1402+
<Switch>
1403+
<Route path="/" exact>
1404+
<Home />
1405+
</Route>
1406+
<Route path="/blog">
1407+
<Blog />
1408+
</Route>
1409+
<Route path="/blog/:title">
1410+
<BlogPost />
1411+
</Route>
1412+
<Route >
1413+
<PageNotFound />
1414+
</Route>
1415+
</Switch>
1416+
</Router>
1417+
);
1418+
};

0 commit comments

Comments
 (0)