0

I am unable to load view using "$location.path" Although my browser URLis getting updated but my content is not getting loaded. Here is the controller code:

var app= angular.module("LoginModule",[]);
app.controller("LoginController",['$scope','$http','$location',function($scope,$http,$location){
        $scope.submitForm= function(valid){
            if(valid){
               $http.get('/admin/dashboard').success(function(data){
                $location.path('dashboard');
                });
            }
        };
}]);

It is changing my URL to "http://example.com/admin#/dashboard" for the same page. My router file code is:

var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/admin', function(req, res) {
  res.render('admin/login', { title: 'Login' });
});


router.get('/admin/dashboard', function(req, res) {
    //res.render('admin/dashboard', { title: 'Welcome to dashboard' });
    res.send("success");
});

module.exports = router;

Please advise I am doing anything wrong.

1
  • Why do you think changing the hashbang in the address bar would trigger a request to your server? Where is your angular routing configuration? Commented Oct 24, 2014 at 15:33

1 Answer 1

2

Per the AngularJS docs at https://docs.angularjs.org/api/ng/service/$location :

Note: Path should always begin with forward slash (/), this method will add the forward slash if it is missing.

so, you need to put the full value in there:

$location.path('/admin/dashboard');

instead of

$location.path('dashboard');
Sign up to request clarification or add additional context in comments.

7 Comments

I tried it already but not working. I must be missing something.
when you do $location.path('/admin/dashboard') what is the resulting URL?
and, are you using ngRoute or ui-router? can you post that code?
I am working on an existing Express project. It is using Express router mechanism. Not sure about the ngrouter (Srry but I am new to angular js)
just want to confirm what you're expecting. you know that $location.path('whatever') is for AngularJS routing, right? It's not supposed to go back to the server from that at all. if you have a route/state defined in ngRoute or ui-router that matches "/admin/dashboard", that is what should be triggering client-side.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.