💫 v5
<Switch>
<Route path="/" exact>
<Redirect to="/quotes" />
</Route>
<Route path="/quotes" exact component={AllQuotes} />
<Route path="/quotes/:quoteId" component={QuoteDetail} />
<Route path="/new-quote" component={NewQuote} />
<Route path="*" component={NotFound} />
</Switch>
💫 v6
<Routes>
<Route path="/" element={<Navigate to="/welcome" />} />
<Route path="/welcome/*" element={<Welcome />}>
<Route path="new-user" element={<p>Welcome, new user!</p>} />
</Route>
<Route path="/products" element={<Products />} />
<Route path="/products/:productId" element={<ProductDetail />} />
</Routes>
💫 v5
import * as React from 'react';
import { Route, Switch, useHistory } from 'react-router';
const app =()=>{
const history = useHistory();
React.useEffect(() => {
history.push('/home/asd');
}, [])
}
💫 v6
import * as React from 'react';
import { Route, Routes, useNavigate } from 'react-router';
const app =()=>{
const navigate = useNavigate();
React.useEffect(() => {
navigate('/home/asd');
}, []);
}
💫 v5
<Switch>
<Route path="/" exact>
<Redirect to="/welcome" />
</Route>
<Route path="/welcome">
<Welcome />
</Route>
<Route path="/products" exact>
<Products />
</Route>
<Route path="/products/:productId">
<ProductDetail />
</Route>
</Switch>
💫 v6
import React from "react";
import { Link, useNavigate } from "react-router-dom";
const Products = () => {
const navigate = useNavigate();
navigate("/welcome", { replace: true });
return (
<section>
<h1>제품 리스트</h1>
<ul>
<li>
<Link to="/products/p1">마들렌</Link>
</li>
<li>
<Link to="/products/p2">휘낭시에</Link>
</li>
<li>
<Link to="/products/p3">까눌레</Link>
</li>
</ul>
</section>
);
};
export default Products;
💫 v5
import * as React from 'react';
import { useRouteMatch } from 'react-router-dom';
const app=()=> {
const match = useRouteMatch();
React.useEffect(() => {
console.log(match.params);
}, [])
return (
<div>
<h2>mainpage</h2>
</div>
)
}
export default app;
💫 v6
import * as React from 'react';
import { Link, useParams } from 'react-router-dom';
const app = ()=> {
const params = useParams();
React.useEffect(() => {
console.log(params);
}, [])
return (
<div>
<h2>mainpage</h2>
</div>
)
}
export default app;
---
[도움 & 참고![](https://velog.velcdn.com/images/hazel123/post/eec65ec0-5d3f-4f5d-86ef-68a533454c6c/image.png)
](https://jforj.tistory.com/241)