How i integrate routes from addon

Hi, i write an addon und generate routes/templates inside this addon. But the routes does not accessable. How can i inject these addon-routes into router.js or respectively make this routes accessable? thx

You can define routes in an addon and they will be merged into the app’s namespace (if they are properly re-exported) however they aren’t added to the route map unless you either:

  1. add them to the app’s route map as usual
  2. do it in the addon in an instance-initializer (pretty sure this works) so any app that uses the addon will automatically add the addon routes to the route map

Alternatively you could use a routable engine, which is really kind of the answer to “an addon that has routes”

Hey dknutsen,

thank you for your help. All this ways i have done in the past and it always worked, but only not in this case.

Now I just had an epiphany. I have do a great mistake. In use of all this ways i become the message “too many recursions” from browser console. The great mistake is that i use the same name for main project an for the used addon. In this case i build a special addon for a customer project. I gave the addon a new name and it works fine now.

Thank you for your fast help

1 Like

Awesome glad you got it working!

@dknutsen Can you show a demo on how to do that within the addon using instance-initializer, please?

Suppose if I included the route using instance-initializer of the main application, then do I have to include for each and every route in the addon. That is if there are 5 different routes in the addon then I have to include all 5 routes in my instance-initializer of the main application.

Yes I think you would. Addons should be explicit about what they’re adding in to the parent app.

Hi @dknutsen, I have an inapp addon which is dependent on the main application. Is there a possibility to run the tests within the addon in isolation using the main application’s testem config and fixtures. Thanks in advance.

Hi @udhay_hari, could you be more specific about what you mean? If all you want is to run the addon test suite with the app testem and fixtures (I’ve never attempted something like that but…) there’s probably a way you could import some/all of that in order to reuse it.

I was under the impression that in-repo addons (if that’s what you mean by in-app addon) could not have their own tests and that the tests MUST exist in the parent context. Secondly I’d strongly consider migrating away from in-repo addons as I don’t think they’ll be supported in the future. The “modern” equivalent would probably be a monorepo with a separate “real” addon.