【发布时间】:2019-02-21 09:23:14
【问题描述】:
如果我创建了一个 react 应用程序,并且在这个应用程序中有一个指向本地 html 文件的链接,一旦这个应用程序在 gh-pages 上发布,由于某些原因说链接不会指向任何地方,它只是将用户重定向到在点击链接之前他所在的页面。
例如:
如果我像这样使用 CRA 创建一个简单的应用程序:
App.js
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
class App extends Component {
render() {
return (
<div className="App">
I'm the homepage
<a id='testlink' href='html2.html'> Go to the second page </a>
</div>
);
}
}
export default App;
在公共文件夹中,我创建了一个新的 html 文件“html2.html”,它只是说
I am the second app !
就是这样,一个简单的应用程序应该在单击链接时从 index.html 跳转到 html2.html。那么这个应用程序在使用npm start 测试时运行良好,如果通过npm run build 提供的静态 html 文件启动它运行良好,但是当部署在 gh-pages 上时,突然链接不会指向任何地方。
Here is the app described above deployed on ghpages
解决此问题的一种方法是在 gh-pages 上分别上传所有应用程序,或使用 react 路由器,但我想知道我是否只是遗漏了一些东西。谢谢你的帮助。
【问题讨论】:
标签: html reactjs href github-pages