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.
config
part if you plan to minify your code later on. – Simon Belanger yesterdaylocalhost: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 tolocalhost:8080
will change the path (with the router) tolocalhost:8080/#/main
and a refresh will work as the request from a refresh will ask forlocalhost:8080/
. You are making a "server" call when accessing the page through a browser. – Simon Belanger yesterday