如何ui-sref一个空URL的状态?

时间:2016-04-22 07:45:23

标签: angularjs angular-ui-router

我的一些状态定义如下:

$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'
        });

接下来,我想点击按钮时返回home页面。这是使用该按钮上的ui-sref属性完成的。 应该分配给ui-sref以使我能够在点击该按钮后返回主页的值应该是什么?

我在以下任何方面都没有取得任何成功:

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

任何建议都将不胜感激!

2 个答案:

答案 0 :(得分:2)

只需使用ui-sref,其中包含您所在州的州名称:

public class SelectMultipleBasePage<T> : ContentPage
{
    public delegate void ImageSelectedHandler(object sender, EventArgs e);
    public event ImageSelectedHandler OnImageSelected;

    public class WrappedItemSelectionTemplate : ViewCell
    {
        private readonly ImageSelectedHandler _parentHandler;
        public WrappedItemSelectionTemplate(ImageSelectedHandler parentHandler)
            : base()
        {
            _parentHandler = parentHandler;

            // ...
            View = st;
        }

        private void OnImageBtnTapped(object sender, EventArgs e)
        {
            //...
            _parentHandler.Invoke(sender, e);
        }

    }
    public static List<WrappedSelection<T>> WrappedItems = new List<WrappedSelection<T>>();
    public SelectMultipleBasePage(List<T> items)
    {
        WrappedItems = items.Select(item => new WrappedSelection<T>() { Item = item, IsSelected = false }).ToList();
        ListView mainList = new ListView()
        {
            ItemsSource = WrappedItems,
            ItemTemplate = new DataTemplate(() => new WrappedItemSelectionTemplate(HandleImageSelected)),
        };
        // ...
    }

    private void HandleImageSelected(object sender, EventArgs e)
    {
        if (OnImageSelected != null)
        {
            OnImageSelected(sender, e);
        }
    }
}

下次,不要犹豫,检查互联网上的文档:) http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.directive:ui-sref

答案 1 :(得分:0)

你的家乡声明如下:

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

代码应为:

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