gpt4 book ai didi

javascript - React Router V6 显示空白页面

转载 作者:行者123 更新时间:2023-12-05 01:53:50 27 4
gpt4 key购买 nike

我遇到了一个问题。我正在尝试使用 React Router,但它一直显示空白页面。这是我的代码:

应用程序.js:

import React from "react";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import HomePage from "./HomePage";

function App() {
return (
<Router>
<Routes>
<Route path="/" element={<HomePage />} />
</Routes>
</Router>

);
};

export default App;

主页.js:

import React from "react";
import {withRouter} from "react-router-dom"

const HomePage = () => {

return <div>hi</div>
}

export default HomePage;

index.js:

import React from "react";
import ReactDom from "react-dom";
import App from './App';


ReactDom.render(<App/>, document.getElementById("root"))

我已经安装了“React Router V6”,谁能告诉我问题出在哪里?感谢所有的帮助。

最佳答案

使用

import { Route, HashRouter as Router, Routes } from "react-router-dom";

<Router>
<Routes>
<Route exact path="/" element={<Main />} />
<Route path="/download" element={<Download />} />
</Routes>
</Router>

关于javascript - React Router V6 显示空白页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70998318/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com