Sohan Shirodkar
Sohan Shirodkar

Reputation: 520

How to ui-sref a state with empty URL?

I have some states defined as follows:

$stateProvider
        .state('home', {
                url: '/'
                , templateUrl: 'modules/trulo/client/views/browse.client.view.html'
        })

        .state('search', {
            url: '/search'
            , templateUrl: 'modules/trulo/client/views/search.client.view.html'
        })

        .state('profile', {
            url: '/profile'
            , templateUrl: 'modules/users/client/views/settings/edit-profile.client.view.html'
        })

        .state('cart', {
                url: '/cart'
                , templateUrl: 'modules/trulo/client/views/cart.html'
        })
        .state('orders', {
                url: '/orders'
                , templateUrl: 'modules/trulo/client/views/orders.html'
        })

        .state('home.myshop', {
            url: '/myshop'
            , templateUrl: 'modules/trulo/client/views/myshop.html'
        });

Next, I want to go back to the home page when I click on a button. This is done using ui-sref attribute on that button. What should be the value that should be assigned to ui-sref to enable me to go back to home page upon clicking that button?

I am not getting any success with any of the following :

<button ui-sref="">Home</button>
<button ui-sref="/">Home</button>
<button ui-sref="home">Home</button>

Any suggestions would be appreciated !

Upvotes: 1

Views: 767

Answers (2)

Lee
Lee

Reputation: 241

Your state for home is declared as follow:

        .state('home', {
                url: '/'
                , templateUrl: 'modules/trulo/client/views/browse.client.view.html'
        })

The code should be:

<button ui-sref="home">Home</button>

Upvotes: 0

Hyukchan Kwon
Hyukchan Kwon

Reputation: 392

Simply use ui-sref with the name of the state which is in your case :

ui-sref="home"

Next time, don't hesitate to check docs in the internet :) http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.directive:ui-sref

Upvotes: 2

Related Questions