Karson074
Karson074

Reputation: 127

How do I change the URL of using $location with angularJS

I am currently trying to set up a table to go to a profile page when you click a row. But $location.url will simply append the 'profile.html' to the end of the current html page and not take me to the profile page. How do I change the current url to allow me to go to my page.

index html:

http://localhost:9080/AgentOnlineApp/index.html

html I get when I click the row:

http://localhost:9080/AgentOnlineApp/index.html#/profile.html

I want:

http://localhost:9080/AgentOnlineApp/profile.html

current AngularJS code:

$scope.selectTableRow = function(agent)
    {

        $location.url('/profile.html');

    }

Upvotes: 0

Views: 69

Answers (2)

Explosion Pills
Explosion Pills

Reputation: 191729

If you want to use the HTML5 history API, you need to set:

$locationProvider.html5Mode(true);

If you actually want to change the location entirely and reload the page, you are not quite using Angular as intended since this wouldn't be a single page app. However, you could do it with window.location = "profile.html"

Upvotes: 0

GeoffreyB
GeoffreyB

Reputation: 1839

You might want to try this to load another page (outside your application):

$window.location.replace("profile.html")

Don't forget to inject $window

Upvotes: 1

Related Questions