Getting Objects by Path
tldr; Use getObjectByPath
to get data for the object that
Decoupled Router resolves to
the provided path
const recipeByPath = await store.getObjectByPath({
objectName: 'node--recipe',
path: '/recipes/fiery-chili-sauce',
// optional parameter to force the data to be fetched from Drupal even if it exists in the local store.
refresh: true,
// optional parameter to include JSON:API query string params to the endpoint to be fetched
params: 'include=field_recipe_category',
});
When getObjectByPath
is called, Drupal State will make a request to Decoupled
Routerโs translate-path endpoint in order to determine the id of the object
associated with the requested path. It will then return data for that object.
The result of the translate-path request is stored in state, so subsequent calls
to getObjectByPath
will not make additional requests to Decoupled Router.
Use of this feature requires installing the Decoupled Router module on your Drupal site.