File tree Expand file tree Collapse file tree 1 file changed +51
-1
lines changed
Expand file tree Collapse file tree 1 file changed +51
-1
lines changed Original file line number Diff line number Diff 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+ } ;
You can’t perform that action at this time.
0 commit comments