0

I have a login form, once the user filled the username and password i am redirecting them to home page.

for that i do like this:

$scope.submitLogin = function (valid) {

        if(!valid) return;

        var data = $scope.login;
        $location.url('/home'); //redirecting to home page.

    }

works fine. But after landing to that page, in case of refresh the page, the url is still exist as http://localhost:3000/home - but instead of loading the page i am getting message as Cannot GET /home - what is the problem here?

How to fix this? or what is the mistake i do here? any one help me to sort this please?

Thanks in advance.

UPDATE

Here is my root provider for reference:

(function () {

    "user strict";

    angular.module("tcpApp", ["ngRoute","ngResource", "ngAnimate"])

    .config(function ($routeProvider, $locationProvider) {

        $locationProvider.html5Mode(true);

        $routeProvider
            .when ("/", {
                templateUrl : "views/login/login.html",
                controller  : "loginController"
        });

        $routeProvider
            .when ("/home", {
                templateUrl : "views/home/home.html",
                controller  : "homeController"
        });

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

})();
user2024080
  • 1
  • 14
  • 56
  • 96

1 Answers1

0

You have to change the redirecting code to:

$location.path('/home');

You're most probably running a default routing setup in which you don't have rewrites on your server setup. If so, there really is not such address. In typical basic single page application there each request to the server loads only e.g. index.html page, and the front-end routing happens by attaching #/something to the address.

If you're using a html5 mode you won't have # in your address, but you have to mind you have to set up rewrites to your index file on your server.

Tomek Sułkowski
  • 7,081
  • 2
  • 17
  • 15