简体   繁体   English

工作箱:为网址格式编写正则表达式

[英]Workbox: writing regular expression for url patterns

I am trying to precache routes. 我正在尝试预缓存路线。 I have successfully precaches the homepage using 我已经成功使用以下方法预缓存了首页

 workbox.precaching.precacheAndRoute(['/']);

and this to match route for homepage 这与首页的路线相匹配

workbox.routing.registerRoute(
 /^\/$/,
  new workbox.strategies.NetworkFirst({
    cacheName: 'static-resources',
  })
);

I still have other top level routes i will like to match but not sure how. 我还有其他顶级路线,我想配对但不确定如何。

localhost/subcategory //subcategory and slug attached to it
localhost/product  //product and slug attached to it
localhost/product-single // and slug attached to it

How do i write the regular expression for the above 我如何为上面的写正则表达式

You could use https://regex101.com/ to help you achieve what you want. 您可以使用https://regex101.com/帮助您实现所需的目标。

A regex like ^localhost(\\/.+)?$ should do the trick ^localhost(\\/.+)?$这样的正则表达式可以解决问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM