我正在创建一个反应应用程序,使用反应路由器。我使用路由器来匹配像:/bankName-:credit
这样的路径,它在本地开发中工作得很好。我的应用程序唯一需要的路径是:/bankName-:credit
,所有其他路径都将访问404
。但是当我将这个应用程序部署到netlify时,默认情况下它会转到/
,并显示一个自定义的404
。一切都很好。但是现在,如果我尝试转到/hdfc-500
,那么它会给出一个netlify而不是page not found
的消息。
我尝试使用_redirects
,就像在netlify文档中提到的那样,但是这是行不通的。
以下是我的路线:-
App.js
<Route path='/:bankCode-:credit' component={NestedRoutes} />
<Route component={NotFound} />
这是我的NestedRoutes
组件:-
const NestedRoutes = ({ match }) => (
<Suspense fallback={<LinearProgress />}>
<Switch>
<Route exact path={`${match.path}/sc-generate`} component={SCGenerate} />
<Route exact path='/:bankCode-:credit' component={Home} />
<Route component={NotFound} />
</Switch>
</Suspense>
)
我在我的_redirects
文件中使用了以下代码:
/* /:bankCode-:credit
但它试图与/:bankCode-:credit
完全匹配
我该怎么做才能解决这个问题?
发布于 2019-06-12 07:56:52
我在这里重现了你的问题,https://codesandbox.io/s/trusting-frost-ls353
解决方案很简单,将一个名为_redirects
的文件添加到包含以下内容的公用文件夹中
/* /index.html 200
您可以找到有关此链接的更多信息。https://www.slightedgecoder.com/2018/12/18/page-not-found-on-netlify-with-react-router/
发布于 2020-08-05 06:52:47
当在netlify中传递url参数时,我遇到了这个问题,并通过删除“。在index.html文件中build文件夹中的href和src链接之前。
希望这能帮助某人。--
发布于 2022-09-14 20:25:32
对于角,此解决方案适用于我在src文件夹中添加_redirects
文件,代码如下
/* /index.html 200
然后确保在您的_redirects资产数组中包含angular.json文件,以便在构建项目时能够包含该文件的副本:
"assets": [
"src/_redirects"
]
您可以找到有关此链接https://docs.netlify.com/integrations/frameworks/angular/的更多信息。
https://stackoverflow.com/questions/56468161
复制