using System.Collections.Generic; using System.Linq; namespace cwebplusApp.Shared.Services { public class PageHistoryManager { private readonly List previousPages; public PageHistoryManager() { previousPages = new List(); } public void Reset() { previousPages.Clear(); } public void AddPageToHistory(string pageName) { previousPages.Add(pageName); } public string GetPreviousPage() { if (CanGoBack()) { // You add a page on initialization, so you need to return the 2nd from the last string previousPage = previousPages.ElementAt(previousPages.Count - 2); previousPages.RemoveAt(previousPages.Count - 1); previousPages.RemoveAt(previousPages.Count - 1); return previousPage; } // Can't go back because you didn't navigate enough return previousPages.FirstOrDefault(); } public bool CanGoBack() { return previousPages.Count > 1; } } }