React-Native 导航(v5) DeepLinking 从 URL 获取参数
知道如何获得正确的参数吗?
我收到此URL并且我想导航到正确参数内的正确屏幕。
网址-> /p-einhell-drill-screwdriver-123456/
我想采用 url 3 个参数的形式:
- URL 是 -> p-einhell-drill-screwdriver-123456/
- seoName ->; einhell 钻头螺丝刀
- id -> 123456
我可以将所有这些都放在一个参数中,但我不能将它们分散到 3 个参数中。 目前我有这个解析器,但它只需要一个参数。
例如:
const config = {
ProductScreen: {
path: ':seoName/', /* p-einhell-drill-screwdriver-123456/ */
parse: {
seoName: (seoName) =>
seoName.split('-').slice(1, -1).join('-'),
URL: (seoName) => seoName,
currentProductId: (seoName) =>
seoName.split('-').pop(),
},
},
}
结果:
<前><代码>参数:{ 网址:未定义 当前产品 ID:未定义 seoName: "einhell-drill-screwdriver" }
Have any ideas how can I get correct params ?
I getting this URL and I want navigate to correct screen within correct params.
URL -> /p-einhell-drill-screwdriver-123456/
I want to take form that url 3 parameters:
- URL which is -> p-einhell-drill-screwdriver-123456/
- seoName -> einhell-drill-screwdriver
- id -> 123456
I can take all of them in one parameter but i can not spread in 3 param.
At this moment I have this parser but It takes only one params.
Forxample:
const config = {
ProductScreen: {
path: ':seoName/', /* p-einhell-drill-screwdriver-123456/ */
parse: {
seoName: (seoName) =>
seoName.split('-').slice(1, -1).join('-'),
URL: (seoName) => seoName,
currentProductId: (seoName) =>
seoName.split('-').pop(),
},
},
}
Result:
params: { URL: undefined currentProductId: undefined seoName: "einhell-drill-screwdriver" }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
parse
下的选项引用配置中定义的参数(例如:seoName
)和查询参数(如果有)。您不能在那里添加任意属性。但是您可以在
seoName
中返回一个对象:然后在组件中的
route.params.seoName
中获取该对象。The options under
parse
refer to the params defined in the config (e.g.:seoName
) and query params if any. You can't add arbitrary properties there.But you can return an object in
seoName
:And then get this object in
route.params.seoName
in your component.