1

Angularjs version 1.3.14, ui-router version 0.2.15, html5mode enabled. When I try http://localhost/firsttime it redirects to http://localhost as fallback

Here is app.js

'use strict';

// Declare app level module which depends on views, and components
angular.module('tt', [
  'ngRoute',
  'tt.home',
  'tt.firsttime',
  'ui.router'
])

.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
    // Routes
    $routeProvider.otherwise({
        redirectTo: '/'
    });

    // set HTML5 history API
    $locationProvider.html5Mode(true);
}]);

Here is firsttime.js

// create our angular app and inject ngAnimate and ui-router 
// =============================================================================
angular.module('tt.firsttime', ['ui.router'])

// configuring our routes 
// =============================================================================
.config(['$stateProvider', '$urlRouterProvider', '$routeProvider', function($stateProvider, $urlRouterProvider, $routeProvider) {
    // catch all route
    // send users to the form page 
    $urlRouterProvider.otherwise('/firsttime');

    $stateProvider
        // route to show our basic form (/firsttime)
        .state('firsttime', {
            url: '/firsttime',
            templateUrl: 'firsttime/form.html',
            //controller: 'formController'
        })
}])

// our controller for the form
// =============================================================================
.controller('formController', ['$scope', function($scope) {
    console.log('FORM controller');
}]);

And here is form.html

<div class="row">
<div class="col-sm-8 col-sm-offset-2">

  <div id="form-container">

      <div class="page-header text-center">
          <h2>Let's Be Friends</h2>

          <!-- the links to our nested states using relative paths -->
          <!-- add the active class if the state matches our ui-sref -->
          <div id="status-buttons" class="text-center">
              <a ui-sref-active="active" ui-sref="firsttime.profile"><span>1</span> Profile</a>
              <a ui-sref-active="active" ui-sref="firsttime.interests"><span>2</span> Interests</a>
              <a ui-sref-active="active" ui-sref="firsttime.payment"><span>3</span> Payment</a>
          </div>
      </div>

      <!-- use ng-submit to catch the form submission and use our Angular function -->
      <form id="signup-form" ng-submit="processForm()">
          <!-- our nested state views will be injected here -->
          <div id="form-views" ui-view></div>
      </form>

  </div>



</div>
</div>

Update Here is the nginx routing block

    location / {
        root   html/app;
        index  index.html;
        try_files $uri /index.html;
    }

1 Answer 1

1

Remove the config block from the app.js that may conflicting with your current route system. You should never use both routing engine together. By looking at your code it seems like you are trying to use ui-router for routing. So by removing app.js config block will potentially solve your issue.

The issue is because of this line

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

After removing code from the app.js you should move below lines to firsttime.js config block, this will enable the html5mode

// set HTML5 history API
$locationProvider.html5Mode(true);
Sign up to request clarification or add additional context in comments.

5 Comments

Had tried, no luck! Has it something to do with nginx config? Updated orig post
@Dewsworld that the issue you need to fix on nginx side.. I;m not familliar with it.. Sorry
I believe the error was due to mixing routeprovider and stateprovider. Upgraded to ui-router, since it looks more promising than ngRoute
@Dewsworld that what I suggested in my answer.. you are using ui-router remove the ngRoute thing thoroughly
@Dewsworld Glad to help you..Thanks :)

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.