Javascript S3桶罐';带路由的负载反应应用程序

Javascript S3桶罐';带路由的负载反应应用程序,javascript,reactjs,amazon-s3,react-router,react-router-dom,Javascript,Reactjs,Amazon S3,React Router,React Router Dom,因此,我目前的情况是,我希望在S3存储桶中显示我的react应用程序。当我将应用程序部署到S3 bucket时,它会给我一个静态URL,我可以看到应用程序,例如 https://s3bucket.www.react-application.cloud/apps/calculationapp/24995X095636Fb9b5821/index.html 在我的例子中,我看到一个空页面,我的假设是,我在index.js文件中配置react路由的方式存在一些问题 index.js const g

因此,我目前的情况是,我希望在S3存储桶中显示我的react应用程序。当我将应用程序部署到S3 bucket时,它会给我一个静态URL,我可以看到应用程序,例如

https://s3bucket.www.react-application.cloud/apps/calculationapp/24995X095636Fb9b5821/index.html
在我的例子中,我看到一个空页面,我的假设是,我在index.js文件中配置react路由的方式存在一些问题

index.js

 const getBasename = path => path.substr(0, path.lastIndexOf('/'));
 ReactDOM.render(
        <BrowserRouter basename={getBasename(window.location.pathname)}>
            <App />
        </BrowserRouter>,
        boostrapElement
    );
const getBasename=path=>path.substr(0,path.lastIndexOf('/');
ReactDOM.render(
,
boostraplement
);
我之所以说这是最有可能的问题,是因为当我简单地使用部署它时

ReactDOM.render(
    <h1> Show me something ! </h1>
    boostrapElement
);
ReactDOM.render(
给我看看!
boostraplement
);
它工作得很好,我可以看到h1

App.js

class App extends Component {
    render() {
        return (
            <React.Fragment>
                <Route key="start-path" path='/' render={(props) => <HomeComponent {...props} filterData='HOME' />} />
                <Route exact key="second-page" path='/react/second' render={(props) => <HomeComponent {...props} filterData='SECOND' />} />
                <Route exact key="third-page" path='/react/third' render={(props) => <HomeComponent {...props} filterData='THIRD' />} />
            </React.Fragment>
        )
    }
}
类应用程序扩展组件{
render(){
返回(
} />
} />
} />
)
}
}

你的帖子根本没有解释你的问题,但我怀疑这可能是你的问题


转到网站所在的S3存储桶,上传文件后,转到属性选项卡并单击静态网站托管选项。选择“使用此bucket托管网站”选项,并向“索引文档”和“错误文档”字段提供index.html。这将确保您对S3的请求,比如说,
/react/second
不会像通常那样尝试访问bucket中的
/react/second
键。

输入index.html没有任何问题,问题是由于S3的URL结构,它无法初始化我的组件网,因为它是静态的,无法更改。它无法通过index.html路由,因为组件将位于index.html/first | index.html/second中。由于上面提到的路由是不可能的,我想我不能显示我的应用程序。我只是猜测,使用react和routing是不可能的,使用纯react而不使用routing是不可能的;流程将是->index.html,它初始化包含路由的index.js,因为它不能被定义为相对路径,所以它不会工作,因为这正是路由与react一起工作的方式。#有用@help=>添加index.html index和error@Static website hosting=>使用此bucket托管网站=>索引文档(index.html)=>错误文档(index.html)