How do I clear the Navigation stack?

后端 未结 5 1264
无人共我
无人共我 2021-02-18 18:03

I have problem for Navigation in my app. I use xamarin.forms how can clean my navigation stack. No use Pop and push. Can I see my full navigation stack ?

5条回答
  •  借酒劲吻你
    2021-02-18 18:23

    This is a function I made to empty the stack and navigate to a specified page. (The use case was the app was de-activated during use and I need to kick the user out)

        public async Task PopAllTo(ViewModel vm)
        {
            if (vm == null) return;
            Page page = PreparePage(vm); //replace 'page' with the page you want to reset to
            if (page == null) return;
            _navigation.InsertPageBefore(page, _navigation.NavigationStack.First());
            await _navigation.PopToRootAsync();
        }
    

提交回复
热议问题