How to populate URLs to use with Javascript

Simply configure module.yml like in this code:

# moduleA module.yml file

all:
  urls:
    overrideMe: moduleA/me

# moduleB module.yml file

all:
  urls:
    moduleBSomething: moduleB/something

# moduleC module.yml file

all:
  urls:
    load: [ 'moduleA', 'moduleB']
    data:
      showX: show/x
      showY: show/y
      overrideMe: show/z

If we are in moduleC module, moduleA and moduleB urls will be loaded before moduleC ones. In the example the moduleA url called overrideMe will be overrided in moduleC.

This would be the output:

var siwapp_urls = {
  moduleBSomething: 'moduleB/something',
  showX: 'show/x',
  showY: 'show/y',
  overrideMe: 'show/z'
};

All of these URLs will be generated with the url_for standard helper, so you can execute AJAX with the same environment used to render normal pages.