Search code examples
angularjsangular-ui-routermeanmeanjs

$urlRouterProvider.otherwise('/'); conflicting with Mean-seo


I am trying to implement Mean-seo and it seems to be working except every time it redirects to home page.

http://localhost:3333/?_escaped_fragment_=/contact-us flashes the contact-us page then redirects to home page.

If I remove

$urlRouterProvider.otherwise('/');

It shows the contact us page but then the home page is just blank.


Solution

  • this seems to solve the problem for me. using this

        $urlRouterProvider.otherwise(function ($injector, $location) {
           //what this function returns will be set as the $location.url
            var path = $location.absUrl();
            if (path.indexOf('_escaped_fragment_') === -1) {
                //instead of returning a new url string, I'll just change the $location.path directly so I don't have to worry about constructing a new url string and so a new state change is not triggered
                return '/';
            }
            // because we've returned nothing, no state change occurs
        });
    

    instead of

    $urlRouterProvider.otherwise('/');