Get the App
SLTechnology News&Howtos  ›  Development  › 

How does js get parameters from a path

Shulou Source: shulou.com Published: 2022-06-01 04:35:42 09月22日 Update

Editor to share with you js how to get parameters from the path, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Get parameters from the path const getPathParams = (path, pathMap, serializer) = > {path = path.split ("/"); pathMap = pathMap.split ("/"); return pathMap.reduce ((acc, crr, I) = > {if (crr [0] = = ":") {const param = crr.substr (1); acc [param] = serializer & serializer [param]? Serializer [param] (path [I]): path [I];} return acc;}, {});}; getPathParams ("/ app/products/123", "/ app/:page/:id") / / {page: 'products', id:' 123'} getPathParams ("/ items/2/id/8583212", "/ items/:category/id/:id", {category: v = > ['Car',' Mobile', 'Home'] [v], id: v = > + v}); / / {category:' Home', id: 8583212} above are all the contents of the article "how to get parameters from a path by js". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Parameters paths articles content not much most more knowledge industry information information channels channels references learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno Shulou Information Docker MySQL