iT邦幫忙

0

React-router相關

當使用react-router-dom時
由於在v6版本後做了一些改變
本來在import {HashRouter,Switch,Route} from 'react-router-dom';
switch會失效
出現Attempted import error: 'Switch' is not exported from 'react-router-dom'的報錯

引入方面為
from:

import { HashRouter,Switch, Route } from "react-router-dom";

to:

import { Routes ,Route } from 'react-router-dom';

並且在Route標籤內的component={頁面連結}也做了修改
標籤方面改為
from:

<Route path="/"  exact component={Home} />

to:

<Route path='/welcome' element={<Home/>} />

尚未有邦友留言

立即登入留言