Home App Docs Blog Github

Dynamic url cannot be picked up in state.location

Hi Team, I was trying to follow the “Dynamic URLs with advanced data fetching” tutorial however I cannot get the dynamic url from “state.location”. I have only got one path which is users, if I do users/test, I couldn’t get the ‘test’ part at all from state.location.path. Do you have any ideas why? Thanks. Regards, Jane

Hi Jane,

Thanks so much for reaching out! Our engineering team is going to investigate why state.location.path isn’t currently working for you. In the meantime, you can use window.location in your logic instead. For your custom JS code, you can change it to:

var url =
  "https://clickfrenzy-public-data-janecf.s3-ap-southeast-2.amazonaws.com/brands.json";
fetch(url)
  .then((res) => res.json())
  .then((data) => {
    state.brands = data.brands;
    var pathArray = window.location.pathname.split("/");
    var slug = pathArray[pathArray.length - 1];
    if (slug) {
      state.brand = state.brands.find((brand) => brand.slug === slug);
      console.log(state.brand);
    }
  });

From there, you’ll need to visit a url with the proper path, not just /brands, such as: https://clickfrenzy.com/au/brands/click-frenzy-julove

Let us know if you have any questions!