Reputation: 670
I am new in angular, i create an app using angularJs (used ngRoute for for routing) it works perfect with links from one page to another, but the problem is when i paste url direct or edit it for browser url bar the browser show "This page can't be found" I used $locationProvider html4 mode for removing # from url. so please help me someone is it because of this or what?
here is my routes
angular
.module("myApp", ["ngSanitize", "ngLoadingSpinner", "ngRoute"])
.config(function ($locationProvider, $routeProvider) {
$routeProvider
.when('/' , {
templateUrl: "templates/index.tpl.html"
})
.when('/work' , {
templateUrl: "templates/work.tpl.html"
})
.when('/work/:id' , {
templateUrl: "templates/workDetail.tpl.html"
})
.otherwise({redirectTo:'/'});
$locationProvider.html5Mode(true);
});
and URl look like this http://127.0.0.1:8080/work/1
Upvotes: 0
Views: 227
Reputation: 455
It sounds like you need to setup your server to properly serve the index file when you directly navigate to those routes. This will cause the server to serve the index.html even if you go to a non root url.
A setup similar to this should work. (Assuming you're using Nginx) https://gist.github.com/calebwoods/5e88b5e323d55ad71195
Note this block especially:
location / {
try_files $uri /index.html;
}
Upvotes: 1