0

在一个 React Static 应用程序中,我在公共文件夹中有一个名为的文件夹admin,其中有一个index.html如下所示:

<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Content Manager</title>
  <script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
</head>
<body>
  <!-- Include the script that builds the page and powers Netlify CMS -->
  <script src="https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js"></script>
  <script>
    if (window.netlifyIdentity) {
      window.netlifyIdentity.on("init", user => {
        if (!user) {
          window.netlifyIdentity.on("login", () => {
            document.location.href = "/admin/";
          });
        }
      });
    }
  </script>
</body>
</html>

和一个config.yml看起来像这样的邻居文件:

backend:
  name: git-gateway
  branch: master

media_folder: 'public/uploads'
public_folder: '/uploads'

collections:
  - name: 'pages'
    label: 'Pages'
    files:
      - file: 'src/cms-pages/HomepageEn.md'
        label: 'HomepageEn'
        name: 'homepageEn'
        fields:
          - {
              label: 'Template Key',
              name: 'templateKey',
              widget: 'hidden',
              default: 'homepageEn-page',
            }
          - { label: Title, name: title, widget: string }
          - { label: Description, name: description, widget: string }
          - { label: Image, name: image, widget: image }
      - file: 'src/cms-pages/HomepageDe.md'
        label: 'HomepageDe'
        name: 'homepageDe'
        fields:
          - {
              label: 'Template Key',
              name: 'templateKey',
              widget: 'hidden',
              default: 'homepageDe-page',
            }
          - { label: Title, name: title, widget: string }
          - { label: Description, name: description, widget: string }
          - { label: Image, name: image, widget: image }

在开发模式下启动应用程序时,npm start一切正常,CMS 可以在'localhost:3000/admin'. 当尝试构建它(react static build)然后提供dist文件夹(serve dist -p 3000 -s)时,我无法再访问它/admin,因为它返回主页服务器端呈现的页面。尝试访问时,/admin/index.html我得到一个301 Moved Permanently (from disk cache). 有什么解决方案吗?

4

0 回答 0