Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在React中引用pdf文件_Javascript_Reactjs_Single Page Application_Filepath - Fatal编程技术网

Javascript 如何在React中引用pdf文件

Javascript 如何在React中引用pdf文件,javascript,reactjs,single-page-application,filepath,Javascript,Reactjs,Single Page Application,Filepath,我有一个Reactjs SPA,其文件结构如下所示: import React, {Component} from 'react'; class Resume extends Component { constructor(props) { super(props); this.state = {}; } render() { return ( <div className={'resum

我有一个Reactjs SPA,其文件结构如下所示:

import React, {Component} from 'react';

class Resume extends Component {
    constructor(props) {
        super(props);

        this.state = {};
    }

    render() {
        return (
            <div className={'resume-container'}>
                <div id={'resume-pdf'}>You can view, download and print my résumé in pdf format in <a
                    href={'./public/resume_english.pdf'}>English</a> and <a href={'#'}>Spanish</a></div>
            </div>
        );
    }
}

export default Resume;

在该应用程序中有一个简单的组件(Resume.js),我希望用户能够在浏览器中查看/下载pdf文件(Resume\u english.pdf)。然而,无论是在本地还是在我计划托管SPA的GitHub页面上,我都无法做到这一点。它总是将我重定向到主页

Resume.js如下所示:

import React, {Component} from 'react';

class Resume extends Component {
    constructor(props) {
        super(props);

        this.state = {};
    }

    render() {
        return (
            <div className={'resume-container'}>
                <div id={'resume-pdf'}>You can view, download and print my résumé in pdf format in <a
                    href={'./public/resume_english.pdf'}>English</a> and <a href={'#'}>Spanish</a></div>
            </div>
        );
    }
}

export default Resume;
import React,{Component}来自'React';
类恢复扩展组件{
建造师(道具){
超级(道具);
this.state={};
}
render(){
返回(
您可以在和中查看、下载和打印我的pdf格式简历
);
}
}
导出默认恢复;

有什么想法可以解决问题吗?我已经尝试导入了,但没有成功。

看起来这是用create react应用程序创建的。如果是这样,则
public
目录中的文件将复制到
build
,而
build
目录将用作站点的根目录。因此,合适的href是
/resume\u english.pdf


只需直接在浏览器中输入url即可。类似于
http://localhost:3000/resume_english.pdf
https://danielsto.github.io/resume_english.pdf

看起来这是用CreateReact应用程序制作的。如果是这样,则
public
目录中的文件将复制到
build
,而
build
目录将用作站点的根目录。因此,合适的href是
/resume\u english.pdf


只需直接在浏览器中输入url即可。类似于
http://localhost:3000/resume_english.pdf
https://danielsto.github.io/resume_english.pdf

它可以在本地工作,但不能在GitHub页面上工作。拥有
href={/resume\u english.pdf}
会导致
https://danielsto.github.io/resume_english.pdf
,即未找到
站点
。存储库是私有的,这可能是问题的一部分吗?取决于github页面repo的配置方式。如果是项目页面(danielsto.github.io/reponame),而不是用户页面(danielsto.github.io),则可以使用相对url
/resume\u english.pdf
,它可以在本地工作,但不能在github页面上工作。拥有
href={/resume\u english.pdf}
会导致
https://danielsto.github.io/resume_english.pdf
,即未找到
站点
。存储库是私有的,这可能是问题的一部分吗?取决于github页面repo的配置方式。如果是项目页面(danielsto.github.io/reponame),而不是用户页面(danielsto.github.io),则可以使用相对url
/resume\u english.pdf