Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routes configuration during runtime #2825

Closed
InternalVoice opened this issue Jun 21, 2016 · 2 comments
Closed

Routes configuration during runtime #2825

InternalVoice opened this issue Jun 21, 2016 · 2 comments

Comments

@InternalVoice
Copy link

I have AngularJS app which builds it's UI according to API input data . All information about routes are inside my input data so I can't configure routes after/during building UI. I need a possibility to configure routes after/during UI building.

@christopherthielen
Copy link
Contributor

christopherthielen commented Jun 22, 2016

You can hang onto the $stateProvider and register states on the fly. If you fetch all the states before synchronizing with the URL, it's pretty easy. If you want to register after the user logs in, for instance, there are some more subtle nuances that may cause difficulty.

Easy mode:

var stateProvider
app.config($stateProvider, $urlRouterProvider) {
  stateProvider = $stateProvider;
  $urlRouter.deferIntercept(); // Dont sync the URL yet
}

app.run(($http, $urlRouter) => {
  // get routes
  $http.get('states.json').then(resp => {
    // got routes; register them with the state provider
    resp.data.forEach(state => stateProvider.state(state));
    // tell ui-router to sync the url and listen for changes
    $urlRouter.listen();
    $urlRouter.sync();
  });
})

See also: https://christopherthielen.github.io/ui-router-extras/#/future

@christopherthielen
Copy link
Contributor

Closing. this is on the radar, and I've provided a workaround

See also #2739 #2711 #146

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants