0

I have an AngularJS 1.0.7 web application. When I load my site in a browser I type www.domainname.com. The browser loads the page and immediately my browser url changes to www.domainname/home.

How can avoid this? I would like the browser shows www.domainname.com when I´m in index.html

UPDATE:

Please see my app.js:

'use strict';


// Declare app level module which depends on filters, and services
angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'myApp.controllers'])
  .config(['$routeProvider', '$httpProvider', '$locationProvider',function($routeProvider, $httpProvider, $locationProvider) {

    // use the HTML5 History API
    $locationProvider.html5Mode(true);   

    $httpProvider.defaults.useXDomain = true;
    delete $httpProvider.defaults.headers.common["X-Requested-With"];           

    $routeProvider.when('/about', {templateUrl: 'partials/about.html', controller: 'AboutCtrl'});    
    $routeProvider.when('/contact', {templateUrl: 'partials/contact.html', controller: 'HomeCtrl'});
    // More routing
    $routeProvider.when('/home', {templateUrl: 'partials/home.html', controller: 'HomeCtrl'});
    // More routing
    $routeProvider.otherwise({redirectTo: '/home'}); 
  }])
  .config(function(AngularyticsProvider) {
    AngularyticsProvider.setEventHandlers(['Console', 'GoogleUniversal']);
  }).run(function(Angularytics) {
    Angularytics.init();
  });
2
  • What does your routing look like? Give us something to work with, please. Also, consider updating AngularJS. Your version is very old. Commented Feb 19, 2015 at 13:33
  • Please, see my updates Commented Feb 19, 2015 at 13:47

1 Answer 1

2

It should work if you replaced:

$routeProvider.otherwise({redirectTo: '/home'});

by

$routeProvider.otherwise({redirectTo: '/'});

and added:

$routeProvider.when('/', {templateUrl: 'partials/home.html', controller: 'HomeCtrl'});

NOTE: and as @isherwood rightly commented below:

$routeProvider.when('/home', {templateUrl: 'partials/home.html', controller: 'HomeCtrl'});

can be removed altogether, to avoid having both '/' and '/home' pointing to the same route.

Sign up to request clarification or add additional context in comments.

1 Comment

This should do it. The last line is a change, though, and not an addition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.