Get category ID from topic - Deprecation notice: controller:navigation/category no longer exists

We currently have

  <script type="text/discourse-plugin" version="1.4.0">

  const controller = container.lookup('controller:topic');
  const controllerNavCategory = container.lookup('controller:navigation/category');
  
  const currCategory = controller?.get('model.category_id') || controllerNavCategory?.get("category.id");
  
  console.log('currCategory ', currCategory )
</script>

This works well, but now I am seeing a warning that

Deprecation notice: controller:navigation/category no longer exists, and this shim will eventually be removed. To fetch information about the current discovery route, use the discovery service instead. [deprecation id: discourse.navigation-category-controller]

How can I update this to work with this new discovery service? Thanks

1 Like

This should work:

const service = api.container.lookup('service:discovery');
const currCategory = service.get("category");
4 Likes