Anna
Anna

Reputation: 889

Browser back button: I always stay on the current page

I am new to Angular and I have this code:

HTML template:
<a href="" ng-click="goToCategories();">See categories</a>

JS File:

$scope.goToCategories= function () {
                CategoriesService.getCategory().then(function () {
                    $state.go('home.cat');
                });
            };

JS File 2:

$stateProvider.state('home.cat', {
        parent: 'logged',
        url: '/cat',
        templateUrl: 'home/home-cat.html',
        ...
    });

The problem is when we are at home-cat.html, the browser back button doesn't work. I just stay in home-cat.html. How to correct this?

Thanks!

Upvotes: 2

Views: 212

Answers (1)

KeniSteward
KeniSteward

Reputation: 179

First is 'logged' a route that has a URL or is it an abstract route?

Second does the place where you are coming from with the link have a unique URL?

Third are you aware you told $state.go to go to a route that doesn't exist?

$state.go('home.cat');

should probably be

$state.go('home.funnel');

If you could setup a plunkr or jsfiddle that would also help :)

Note: you don't need

<a href="" ng-click="goToCategories();">See categories</a>

you can simply use

<a ui-sref="home.funnel">See categories</a>

or

<a ui-sref="home.funnel({ param: value})">See categories</a>

docs: https://github.com/angular-ui/ui-router/wiki/Quick-Reference#ui-sref

Upvotes: 2

Related Questions