【发布时间】:2019-06-05 21:19:34
【问题描述】:
我正在创建一个使用反应路由器的反应应用程序。我正在使用路由器来匹配:/bankName-:credit 之类的路径,它在本地开发中运行良好。我的应用程序唯一需要的路径是:/bankName-:credit,其他所有路径都将命中404。
但是,当我将此应用程序部署到 netlify 时,默认情况下它会转到 / 并显示自定义 404。这都很好。但是现在,如果我尝试转到 /hdfc-500,那么它会给出一条 netlify not found 消息,即 page not found。
我尝试使用_redirects 中提到的netlify docs,但这不起作用。
这是我的路线:-
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完全匹配
我应该怎么做才能解决这个问题?
【问题讨论】:
标签: reactjs deployment react-router netlify netlify-cli