Reputation: 13431
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:
/apps
/apps/:appname
/app/:appname
/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:
I'm trying to put a jsfiddle together but it's a hard concept to put in a jsfiddle.
Upvotes: 4
Views: 1334
Reputation: 13431
Thinking more about this, having solved our problem on a different way, it is just getting clear to me that my request just isn't possible.
Upvotes: 1