frontend routing isn't the same as backend routing.
The easiest way to think of frontend routing is "nested views" rather than nested resources.
So, as for getting your data (if you don't already have your data), you need a route file at this path:
app/routes/location/visits.js (I think, you can also ember g route location/visits
and see what happens)
Then in your route:
import Route from '@ember/routing';
export default class LocationVisitsRoute extends Route {
// this is the route lifecicle hook that actually gets the data
// more on that here: https://guides.emberjs.com/release/routing/
async model(params) {
// this assumes that your location route loads the location resource
// similar to how we're trying to load the visits resources is this route.
let locationId = this.modelFor('location').location.id;
// you could also get the location id from params,
// but I don't remember the exact path where the id would live.
console.log(params);
// this is kind of hacky, and I wouldn't really recommend it, as there may
// be concurrency issues. but this technique was taken from here:
// https://discuss.emberjs.com/t/current-way-to-handle-nested-resources/7477/7
this.store.adapterFor('visit').set('namespace', `/api/locations/${locationId}`);
let visitsForLocation = await this.store.findAll('visit');
return {
visits: visitsForLocation,
};
}
}
Then in your template for visits, you can do
{{#each model.visits as |visit|}}
<h1>{{visit.name}}</h1>
{{/each}}
alternatively, if you're using { json:api }
, you can just specify the links
attribute, and things should "just work": How to use Ember Data with Nested Resources
So, all in all, if you are using { json:api }
, configuring your payload to tell the client where resources/relations are is really the best way.