链接在构建后不起作用,但它在 localhost:3000 中有效
我使用 react-router-dom 组件
使用以下方法构建项目:
npm run build
应用程序.js:
return (
<div>
<Router >
<Header/>
<Route exact path="/" component={Home}/>
<Route path="/about" component={About}/>
<Route path="/join" component={Join}/>
<Route path="/advertisement" component={Advertisement}/>
<Route path="/contact" component={Contact}/>
<Route path="/details" component={Details}/>
</Router>
</div>
);
}
和其他组件中的链接:
<ul>
<li><Link to='/'>home</Link></li>
<li><Link to='/about'>about us</Link></li>
<li><Link to='/join'>join</Link></li>
<li><Link to='/advertisement'>ads</Link></li>
<li><Link to='/contact'>contact us</Link></li>
</ul>
包.json
"homepage": ".",