How can I implement virtual routing like Angular/React in my ecommerce store?

How can I’ve Angular/React like virtual routing in Shopify?

Please consider below urls:

  1. https://example.com/collection/bags

  2. https://example.com/collection/bags/wallets/brown

  3. https://example.com/collection/bags/test/123/more

  4. https://example.com/collection/bags/something/else/diff

all these urls should open (not redirect)

https://example.com/collection/bags

but the url in the address bar should not change.

sort of https://example.com/collection/bags/*https://example.com/collection/bags