相关疑难解决方法(0)

尝试进入 React 应用程序路由时出现 404

我刚刚在 c-panel 上部署了我的 React 应用程序构建。该应用程序包括不同的路线,每次我尝试到达其中一条路线时,我都会得到404 Not found。例如,如果我尝试访问http://example.com/它,它将进入该网站,如果我按下链接到它的按钮,http://example.com/articles它将起作用。http://example.com/articles但是,如果我尝试从我共享的链接获取或仅输入此地址,我会得到404 Not found. 当我在本地主机上运行开发模式时,不会发生这种情况。

我更改了 package.json 中的主页 url "homepage": "http://example.com",,但没有效果。

我的应用程序根目录包含<Router>

function App() {
  return (
    <Provider store={store}>
      <Router>
        <React.Fragment>
          <CssBaseline />
          <Header title="exampletitle" />
          <MobileHeader />
          <Main />
          <BottomNavbar />
        </React.Fragment>
      </Router>
    </Provider>
  );
}
Run Code Online (Sandbox Code Playgroud)

这是由路由操纵的 Main.js 组件。

function Main(props) {
  return (
    <div>
      <Switch>
        <Route exact path="/" component={Homepage} />
        <Route exact path="/about" component={About} />
        <Route exact path="/signup" component={Registerpage} />
        <Route …
Run Code Online (Sandbox Code Playgroud)

nodes reactjs react-router

6
推荐指数
1
解决办法
1万
查看次数

如何在 cpanel 上部署 nextjs 应用程序?

我按照这些步骤在 cPanel 上部署了我的 nextjs。

  1. 转到 package.json 并添加以下行: "homepage": "http://afsanefadaei.ir"

  2. 运行next build以将.next文件夹作为我的构建文件夹

  3. 转到cpanel >> file manager >> public_html文件夹并将文件夹的内容上传.next到此目录

  4. 添加或编辑此文件:.htaccess到:

    在此处输入图片说明

但是当我访问该网站时,我遇到了以下情况:

在此处输入图片说明

你知道这有什么问题吗?

deployment .htaccess cpanel reactjs next.js

1
推荐指数
2
解决办法
7614
查看次数

标签 统计

reactjs ×2

.htaccess ×1

cpanel ×1

deployment ×1

next.js ×1

nodes ×1

react-router ×1