我是React的新手,并尝试在react-dom-router中使用参数。但是每次我尝试使用参数调用URL时,总是会收到“无法获取/ ...”错误。
这是我的index.js
import React from 'react';
import { BrowserRouter } from "react-router-dom";
import ReactDOM from 'react-dom';
import App from "./app";
ReactDOM.render(
<BrowserRouter>
<App/>
</BrowserRouter>,
document.getElementById('root')
);
if (module.hot) {
module.hot.accept();
}
这是我的app.js
import React, {Component, Fragment} from 'react';
import { BrowserRouter, Switch, Route, Link, useParams} from "react-router-dom"
import Profile from "./pages/Profile/Profile";
import About from "./pages/About/About";
const App = () => (
<Fragment>
<Switch>
<Route path="/:profile" component={Profile} />
<Route path="/" component={About} />
</Switch>
</Fragment>
);
export default App;
答案 0 :(得分:0)
我通过在webpack配置中添加以下内容来解决此问题:
devServer: {
historyApiFallback: true
}