Search code examples
amp-html

AMP: use route info from url


For a URL /products/123, can we grab and use that 123 from the URL to fetch and display the corresponding data? If I understand correctly, making this dynamic allows handling user clicks on related products with a setState, allowing one to reuse the template.


Solution

  • Query parameters can be accessed using AMP variable substitution, which is supported by the amp-list component. In your case you could provide a product id via query parameter:

    /products?product=123456

    ...and then use amp-list to render the product details:

    <amp-list src="https://foo.com/list.json?product=QUERY_PARAM(product)">
      ...
    </amp-list>