0

In our team, we want to use angular-ui-router to assign a "state" by reading the url without hashbangs or html5mode, so that 1. We programmatically assign controllers based on "normal" urls and 2. We support ie9

We can't support hashbangs (which would give use ie9 support) because we are running this on a "non-spa website" and the urls are rendered server side. We literally just want to assign a state by reading a normal url on page load.

This seems trickier than I previously thought. Consider the following routes:

       //Parent view

        .state('abc', {
            abstract: true,
            controller: 'MainController'
        })

        //Search

        .state('abc.Search', {
            url: '/booking/search',
            controller: 'SearchController'
        })

Here is the goal: We want the whole path http://website.com/booking/search to pick up the state NOT http://website.com/#/booking/search, and we can't remove the # by adding html5mode.

If we try to add html5mode the page keeps refreshing in ie9 (we dont support ie8).

Now I know that we can remove state-routing and go back to adding ng-controller to the template, however we are in a unique position where we need to be able to programmatically assign controllers based on the url. This is the advantage on using angular-ui-state router.

Thanks in advance.

CarbonDry
  • 850
  • 1
  • 12
  • 25
  • "How to use angular ui router on “normal sites” without HTML5 mode?" — You can't. "We support ie9" — Microsoft doesn't. Consider adding conditional comments to add your JS only in modern browsers. – Quentin Jun 19 '17 at 10:09
  • 1
    If your application is handling routing in server-side, then, you shouldn't need a client router at all. Just run a different app on each server side route. – Hitmands Jun 19 '17 at 10:14
  • 1
    As far as your routing is handled server-side, why don't you simply assign the correct controller server-side as well? – Deblaton Jean-Philippe Jun 19 '17 at 10:28
  • @DeblatonJean-Philippe Assigning the controller is what we need to do, but could you elaborate? I know we can add ng-controller back to the tempate (which is rendered server-side) but then we lose the $state and $stateProvider features that come with angular-ui-router which we have been using successfully in ie10+... – CarbonDry Jun 19 '17 at 10:36
  • 1
    I'd suggest you to use ng-controller, and assign it server-side as you were doing before. What are the features you want to keep from `$stateProvider`? – Deblaton Jean-Philippe Jun 19 '17 at 13:02
  • I think that is going to be the case... We wanted to use angular-ui-router because we are going to be added SPA capabilities to the app soon. We also want to parse query params from the url using the $stateProvider api – CarbonDry Jun 19 '17 at 13:07
  • Hi @DeblatonJean-Philippe if you can make your response an answer, I will give you a tick. – CarbonDry Jun 20 '17 at 14:08
  • @CarbonDry I don't think this comment deserves upvotes or to be an answer, but thanks for asking ;-) – Deblaton Jean-Philippe Jun 20 '17 at 14:12

0 Answers0