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:
- add them to the app’s route map as usual
- 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”
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
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.