Is it possible to add and remove routes after the application is already running?
We have an application, it is already running in the browser, and we dynamically load extra scripts when the user starts a widget in the app. (see it as the app store of google or apple, and you click on an app and it opens the app, with it's own scripts).
Now 1 of those things an app needs to do, is have routes inside the app.
The current routing:
- app store:
/apps
- app store's app detail:
/apps/:appname
- the app's url:
/app/:appname
- a route within an app:
/app/:appname/:...
this could be:/app/notes/create
or/app/contacts/edit
or/app/contacts/new
Each app can have different routes, not necessarily on the same level, they can be /app/news/foreign/latest
Each app has to be separate, and the routes should therefor be loaded in when the app's scripts load. we managed to do this for controllers and directives via the $controllerProvider.register
method to add controllers to the application after the application is already started.
But the $routeProvider
is not available after the config phase of the app.
I managed to make it public in a dirty way:
var myApp = angular.module('myApp', []);
myApp.config(function AppConfig($routeProvider) {
myApp.routeProvider = $routeProvider;
});
This way it looks like I can register routes, but as I expected, any of these urls don't work when you enter them manually in the browser, as the angular application itself does not know these routes at run time.
In fact, these routes are only available after the /app/:appname
route was triggered which then loads the scripts and adds the extra route.
TL;DR:
- Is it possible to cleanly register new routes after the app has started
- Does anyone know a solution to direct linking to one of these subroutes, when they are not known to the application 'yet'?
I'm trying to put a jsfiddle together but it's a hard concept to put in a jsfiddle.