netlify 重定向在 React 应用程序中不起作用

netlify redirects not working in react app

我的程序员之旅才刚刚开始,这是我的第一次 post,可能不会是最后一次。
所以这是问题。我使用 create-react-app 在 React 中构建投资组合项目。这不是必要的技术,但我想通过将简单的网站移动到 React 来练习。我使用多页路由(只有 2 页)。我使用自定义域,因为这将是我母亲美发沙龙的网站,并且 Netlify 免费托管。这里是 link:
https://bozena.net.pl/
我为画廊 (galeria) 的重定向而苦苦挣扎。
https://bozena.net.pl/pages/Gallery
如果我直接去那里或刷新,它不起作用。我使用 API 作为图片,如果这很重要的话。我发现我需要在构建文件夹中使用 _redirects 文件,但我无法弄清楚它的确切语法(我检查了关于 _redirects 的 Netlify 文档)。现在我的 _redirects 文件看起来像这样:

/                   https://bozena.net.pl/#price-div 
/                   https://bozena.net.pl/#contact
/(whats here?)      https://bozena.net.pl/Gallery  

我为这个画廊尝试了不同的路径,比如 /pages/Gallery(这里是画廊的 jsx 文件)但我没有找到任何工作。价格 div 和联系方式在主页上 div,此说明将带我到主页。有人帮我让这个画廊 link 工作吗?
这是整个页面的代码:
https://github.com/kadynski/Hairdresser-app code 加粗 斜体

quote Draft saved I'm at a beggining of my programmer journey, this is my firt post, probably not last. So here is problem. I build portfolio project in React, using create-react-app. It was not necessary technology but I wanted to practice, by moving simple site to React. I used routes for multipage (there is only 2 pages). I used custom domain, because this will be site for my mother hairdresser salon, and Netlify free hosting. Here is link: https://bozena.net.pl/ I struggle with redirection for gallery (galeria). https://bozena.net.pl/pages/Gallery If I go directly there or refresh, its not working. I used API for pictures, if thats matter. I found out I need to use _redirects file in build folder, but I cant figure out exact syntax for this (I checked Netlify documentation about _redirects). For now my _redirects file looks like this:

/                   https://bozena.net.pl/#price-div 
/                   https://bozena.net.pl/#contact
/(whats here?)      https://bozena.net.pl/Gallery  

我为这个画廊尝试了不同的路径,比如 /pages/Gallery(这里是画廊的 jsx 文件)但我没有找到任何工作。价格 div 和联系方式在主页上 div,此说明将带我到主页。有人帮我让这个画廊 link 工作吗? 这是整个页面的代码: https://github.com/kadynski/Hairdresser-app

试试这个

  1. 在您的项目中添加一个文件 public 文件夹将其命名为 _redirects
  2. 然后粘贴此代码并保存(并部署)/* /index.html 200

来源:https://answers.netlify.com/t/netlify-page-not-found-when-sharing-react-router-dom-based-links/11744/2