Reactjs 将创建react应用程序与react路由器一起部署到Godaddy路由问题
我使用“npm运行构建”生成的文件在Godaddy中部署了我的应用程序。当我从应用程序访问路由时,它工作正常。然而,当我刷新应用程序时,它会给我一个404页面未找到错误。我尝试添加.htaccess文件,但仍然不起作用 以下是路由器代码:Reactjs 将创建react应用程序与react路由器一起部署到Godaddy路由问题,reactjs,react-router,Reactjs,React Router,我使用“npm运行构建”生成的文件在Godaddy中部署了我的应用程序。当我从应用程序访问路由时,它工作正常。然而,当我刷新应用程序时,它会给我一个404页面未找到错误。我尝试添加.htaccess文件,但仍然不起作用 以下是路由器代码: <Router> <div> <Route exact path="/" component={Splash} /> <Route path="/signin" component={
<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>
()} />
()} />
()} />
()} />
如果您正在使用而不是手动刷新,则会得到404,因为浏览器试图调用请求不存在的页面
您可以查看这个有趣的链接,它将帮助您更好地理解:
如果您正在使用而不是手动刷新,则会得到404,因为浏览器试图调用请求不存在的页面 您可以查看这个有趣的链接,它将帮助您更好地理解:
创建一个文件。htaccess 使用终端“nano.htaccess” 创建文件后。粘贴下面的代码
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
重新启动发动机
重写基/
重写规则^index.html$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.html[L]
省省吧
然后将此文件上载到public_html文件夹中
使用godaddy文件管理器创建一个文件.htaccess 使用终端“nano.htaccess” 创建文件后。粘贴下面的代码
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
重新启动发动机
重写基/
重写规则^index.html$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.html[L]
省省吧
然后将此文件上载到public_html文件夹中
使用godaddy文件管理器