黑馬程序員前端React視頻教程,react零基礎(chǔ)入門原理詳解到好客租房項(xiàng)目實(shí)戰(zhàn)
2023-08-10 01:10 作者:RangerE1even | 我要投稿

React18中index.js渲染的寫法(避免運(yùn)行在react17中):const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(
? ? <App></App>
)
在react-router-dom V6 版本中
嵌套路由的寫法:<Routes>
//父組件后加/*
? ? ? ? ? <Route path='/home/*' element={<Home></Home>}></Route>
? ? ? ? </Routes>
//子組件//
?export default class Home extends React.Component {
? ? render() {
? ? ? ? return <div>這是首頁
? ? ? ? ? ? {/* 渲染子路由 */}
? ? ? ? ? ? <Routes>
/*子組件的path直接 /組件名 */
? ? ? ? ? ? ? ? <Route path='/news' element={<News></News>}></Route>
? ? ? ? ? ? </Routes>
? ? ? ? </div >
? ? }
}
標(biāo)簽: