使用 react-router 部署 create-react-app 到 Godaddy 路由问题 [英] Deploy create-react-app with react-router to Godaddy routing issue
问题描述
我使用从npm run build"生成的文件在 Godaddy 中部署了我的应用程序.当我从应用程序访问路线时,它工作正常.但是,当我刷新应用程序时,它给了我一个 404 页面未找到错误.我尝试添加 .htaccess 文件,但它仍然不起作用.
这是路由器代码:
<路由器><div><路由精确路径="/" component={Splash}/><Route path="/signin" component={SignInView}/><Route path="/signup" component={SignUpView}/><Route path="/dashboard" render={() =>(<TabbedView tabIndex={0} {...this.props}/>)}/><Route path="/activities-dashboard" render={() =>(<TabbedView tabIndex={1} {...this.props}/>)}/><Route path="/new-activity" render={() =>(<TabbedView tabIndex={2} {...this.props}/>)}/><Route path="/profile" render={() =>(<TabbedView tabIndex={3} {...this.props}/>)}/><Route path="/activities/:value" component={CircularList}/>
</路由器>
创建文件 .htaccess
使用终端'nano .htaccess'创建文件后.粘贴下面的代码
重写引擎开启重写基数/重写规则 ^index.html$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d重写规则./index.html [L]</IfModule>
保存
然后将此文件上传到 public_html 文件夹中通过使用godaddy文件管理器
I deployed my app in Godaddy using the files generated from "npm run build". When I access routes from the app, it works fine. However, when I refresh the app it gives me a 404 page not found error. I tried adding the .htaccess file, but it still doesn't work.
Here is the router code:
<Router>
<div>
<Route exact path="/" component={Splash} />
<Route path="/signin" component={SignInView} />
<Route path="/signup" component={SignUpView} />
<Route path="/dashboard" render={() => (<TabbedView tabIndex={0} {...this.props} />)} />
<Route path="/activities-dashboard" render={() => (<TabbedView tabIndex={1} {...this.props} />)} />
<Route path="/new-activity" render={() => (<TabbedView tabIndex={2} {...this.props} />)} />
<Route path="/profile" render={() => (<TabbedView tabIndex={3} {...this.props} />)} />
<Route path="/activities/:value" component={CircularList} />
</div>
</Router>
create a file .htaccess
using terminal 'nano .htaccess' after create file. paste the below code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Save it
then upload this file in public_html folder by using godaddy file manger
这篇关于使用 react-router 部署 create-react-app 到 Godaddy 路由问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!