Hi All,
I’ve just been making my way through the Super Rentals tutorial (updated to v3.17) and I’m having an issue with dynamic segments in one of the routes.
Essentially the application runs fine, and I’m presented with the main page which has the list of rentals in our example. If I select one of the properties it navigates to the detail page (i.e. detail route) and the page renders correctly. The issue is that if I refresh the page at that point, or manually navigate to the detailed route URL without going through the main page then the page does not render at all.
Looking at the inspector the model request fails; the inspector says that the Promise to fetch the JSON failed. Here’s where the fetch call is made:
export default class RentalRoute extends Route {
async model(params) {
let response = await fetch(`/api/rentals/${params.rental_id}.json`);
let { data } = await response.json();
let { id, attributes } = data;
let type;
if (COMMUNITY_CATEGORIES.includes(attributes.category)) {
type = 'Community';
} else {
type = 'Standalone';
}
return { id, type, ...attributes };
}
}
I initially picked up the issue because my Acceptance Test failed, which attempts to navigate directly to a detail page.
I’m convinced (but maybe naively) that the fetch call which is attempting to dynamically filter the JSON does not work. I believe the reason that I can navigate to the main page and then the subpage without issue is that Ember knows that it already has the model and so is not attempting to “refetch” the data.
I have checked Github and the app/routes/rental.js is on the Ember Tutorial repo is exactly the same as mine.
I’ve been looking at this on and off for several days, and I’m pretty persistent, but I thought it might be useful to reach out for some help. If anyone has any idea as to why I am seeing this behaviour then please let me know.
Thanks,
Dave