Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redirect Gatsby尾部斜杠重定向问题仅在部署版本上存在_Redirect_Amazon S3_Deployment_Gatsby - Fatal编程技术网

Redirect Gatsby尾部斜杠重定向问题仅在部署版本上存在

Redirect Gatsby尾部斜杠重定向问题仅在部署版本上存在,redirect,amazon-s3,deployment,gatsby,Redirect,Amazon S3,Deployment,Gatsby,在我的盖茨比应用程序中,我想要以下路线: /branchs-显示门店的分支位置 /branchs/:id-显示有关特定分支的信息 为此,我有以下文件夹结构: src pages branches index.tsx 在index.tsx中,我有: import React from 'react' import { Router } from '@reach/router' const Comp = (props: { path: any }) =&g

在我的盖茨比应用程序中,我想要以下路线:

  • /branchs
    -显示门店的分支位置
  • /branchs/:id
    -显示有关特定分支的信息
为此,我有以下文件夹结构:

src
   pages
      branches
         index.tsx
index.tsx
中,我有:

import React from 'react'
import { Router } from '@reach/router'

const Comp = (props: { path: any }) => {
    return <pre>{JSON.stringify(props, null, 2)}</pre>
}

export default () => {
    return (
        <Router>
            <Comp path="/branches" />
            <Comp path="/branches/:id" />
        </Router>
    )
}

因此,当我运行《盖茨比开发》(gatsby develop)时,一切都按预期运行。我可以访问
/branchs
/branchs/4
,看到我所期望的,
Comp
组件显示一些路由信息:

但是,当使用gatsby build和gatsby-plugin-s3deploy--yes运行部署到S3时,我进入了一个重定向循环:

这里的问题是什么?我如何解决


(我曾经尝试过
gatsby插件强制尾部斜杠
gatsby插件删除尾部斜杠
插件,但都没有效果)

我从Netlify上的主机上知道,有一些设置可以控制如何处理尾部斜杠。错误应该在S3设置中。我从Netlify上的主机上知道,有一些设置控制如何处理尾部斜杠。错误应该在S3设置中。
// Implement the Gatsby API “onCreatePage”. This is
// called after every page is created.
exports.onCreatePage = async ({ page, actions }) => {
    const { createPage } = actions
    // page.matchPath is a special key that's used for matching pages
    // only on the client.
    if (page.path.match(/^\/branches/)) {
        page.matchPath = '/branches/*'
        // Update the page.
        createPage(page)
    }
}
{
  "path": "/branches",
  "uri": "/branches",
  "location": {
    "pathname": "/branches/",
    "search": "",
    "hash": "",
    "href": "http://localhost:1337/branches/",
    "origin": "http://localhost:1337",
    "protocol": "http:",
    "host": "localhost:1337",
    "hostname": "localhost",
    "port": "1337",
    "state": null,
    "key": "initial"
  }
}