0

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

3
  • Can you post your routes along with the sample url? Commented Jan 31, 2017 at 17:13
  • Coded added to my question. please check Commented Jan 31, 2017 at 17:20
  • brother already added. Commented Jan 31, 2017 at 17:29

1 Answer 1

1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.