Angularjs: determine the route after the config application has passed

Can I 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 additional scripts when the user launches the widget in the application. (see it as a Google or Apple app store, and you click on the app and it opens the app with its own scripts).

Now, one of the things an application needs to do is have routes inside the application.

Current Routing:

  • application store: /apps
  • app store app details: /apps/:appname
  • Application URL: /app/:appname
  • application route: /app/:appname/:... it can be: /app/notes/create or /app/contacts/edit or /app/contacts/new

Each application can have different routes, not necessarily at the same level, they can be /app/news/foreign/latest

Each application must be separate, and routes must be loaded when loading application scripts. we managed to do this for controllers and directives using the $controllerProvider.register method to add controllers to the application after the application is already running.

But $routeProvider not available after the application configuration phase.

I managed to do this in a publicly dirty way:

 var myApp = angular.module('myApp', []); myApp.config(function AppConfig($routeProvider) { myApp.routeProvider = $routeProvider; }); 

Thus, it seems that I can register the routes, but, as I expected, any of these URLs does not work when you enter them manually in the browser, since the corner application itself does not know these routes at runtime.

In fact, these routes are only available after the /app/:appname route /app/:appname , which then loads the scripts and adds an additional route.

TL DR:

  • Is it possible to cleanly register new routes after starting the application
  • Does anyone know a solution to directly reference one of these subordinate routes when they are not yet known to the application?

I am trying to put jsfiddle together, but it is a difficult idea to insert jsfiddle.

+4
source share
1 answer

Thinking about it, solving our problem differently, it just becomes clear to me that my request is simply impossible.

  • you cannot refer to an unregistered route
  • registration of routes can subsequently be performed, but not as clean as using routeProvider in the module configuration section.
+1
source

Source: https://habr.com/ru/post/1499156/


All Articles