Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am developing a angular 1.5 app with typescript and ui-router.

Here is my route.ts file

export class Route {

  static $inject = ['$location'];

  constructor(private $stateProvider: ng.ui.IStateProvider, private $urlRouterProvider: ng.ui.IUrlRouterProvider, private $locationProvide: ng.ILocationProvider) {
    this.init();
    this.$locationProvide.html5Mode({
        enabled: true,
        requireBase: false
        });
  }

  private init(): void {
    this.$stateProvider.state('/main', Route.defaultState());

    this.$urlRouterProvider.otherwise('/main');
  }

  private static defaultState(): ng.ui.IState {
    return {
        url: "/main", 
        template: "<h1>Hello from Main</h1>"
    }
  }


}

angular.module('app')
.config(($stateProvider: ng.ui.IStateProvider, $urlRouterProvider: ng.ui.IUrlRouterProvider, $locationProvider:ng.ILocationProvider) => {
    return new Route($stateProvider, $urlRouterProvider, $locationProvider)
});

and in the module.ts

import * as angular from 'angular';
import 'angular-ui-router';

angular.module('app.services', []);
angular.module('app', ['app.services', 'ui.router']);

At the first of the load, the app goes to http://localhost:8080/main but if i reload, the app shows "Cannot GET /main"

No exception is thrown. Do you have any idea why this could happen? I don't have any base set in the html.

Thanks in advance.

share|improve this question
    
This is not an issue on Angular part but on your server part. Your server needs to know that a request on /main is actually served by /. At this point, the setup required is dependent on the web server technology and we need more information to guide you through it. Also, be careful on the config part if you plan to minify your code later on. – Simon Belanger yesterday
    
I am not making any server call yet. This is static HTML5Mode routing. Please let me know what extra information I should provide. – Jhankar yesterday
    
Whatever is serving localhost:8080 knows how to serve / but not /main. This is why you hitting refresh give you a 404. If you disabled HTML5 Mode routing, a request to localhost:8080 will change the path (with the router) to localhost:8080/#/main and a refresh will work as the request from a refresh will ask for localhost:8080/. You are making a "server" call when accessing the page through a browser. – Simon Belanger yesterday
    
Thanks for the comment. But How could I fix the 404 in html5mode other than going back with hash(#)? – Jhankar yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.