internal static List <string> CollapsePath( string[] myRoute, IEnumerable <string> currentRouteStack, bool removeUserDefinedRoute) { var localRouteStack = currentRouteStack.ToList(); for (var i = localRouteStack.Count - 1; i >= 0; i--) { var route = localRouteStack[i]; if (Routing.IsImplicit(route) || (Routing.IsDefault(route) && removeUserDefinedRoute)) { localRouteStack.RemoveAt(i); } } var paths = myRoute.ToList(); // collapse similar leaves int walkBackCurrentStackIndex = -1; if (paths.Count > 0) { walkBackCurrentStackIndex = localRouteStack.IndexOf(paths[0]); } while (paths.Count > 1 && walkBackCurrentStackIndex >= 0) { if (localRouteStack.Count <= walkBackCurrentStackIndex) { break; } if (paths[0] == localRouteStack[walkBackCurrentStackIndex]) { paths.RemoveAt(0); } else { break; } walkBackCurrentStackIndex++; } return(paths); }
public static ShellNavigationState GetNavigationState(ShellItem shellItem, ShellSection shellSection, ShellContent shellContent, IReadOnlyList <Page> sectionStack, IReadOnlyList <Page> modalStack) { List <string> routeStack = new List <string>(); bool stackAtRoot = sectionStack == null || sectionStack.Count <= 1; bool hasUserDefinedRoute = (Routing.IsUserDefined(shellItem)) || (Routing.IsUserDefined(shellSection)) || (Routing.IsUserDefined(shellContent)); if (shellItem != null) { var shellItemRoute = shellItem.Route; routeStack.Add(shellItemRoute); if (shellSection != null) { var shellSectionRoute = shellSection.Route; routeStack.Add(shellSectionRoute); if (shellContent != null) { var shellContentRoute = shellContent.Route; routeStack.Add(shellContentRoute); } if (!stackAtRoot) { for (int i = 1; i < sectionStack.Count; i++) { var page = sectionStack[i]; routeStack.AddRange(CollapsePath(Routing.GetRoute(page), routeStack, hasUserDefinedRoute)); } } if (modalStack != null && modalStack.Count > 0) { for (int i = 0; i < modalStack.Count; i++) { var topPage = modalStack[i]; routeStack.AddRange(CollapsePath(Routing.GetRoute(topPage), routeStack, hasUserDefinedRoute)); for (int j = 1; j < topPage.Navigation.NavigationStack.Count; j++) { routeStack.AddRange(CollapsePath(Routing.GetRoute(topPage.Navigation.NavigationStack[j]), routeStack, hasUserDefinedRoute)); } } } } } if (routeStack.Count > 0) { routeStack.Insert(0, "/"); } return(new ShellNavigationState(String.Join("/", routeStack), true)); List <string> CollapsePath( string myRoute, IEnumerable <string> currentRouteStack, bool userDefinedRoute) { var localRouteStack = currentRouteStack.ToList(); for (var i = localRouteStack.Count - 1; i >= 0; i--) { var route = localRouteStack[i]; if (Routing.IsImplicit(route) || (Routing.IsDefault(route) && userDefinedRoute)) { localRouteStack.RemoveAt(i); } } var paths = myRoute.Split('/').ToList(); // collapse similar leaves int walkBackCurrentStackIndex = localRouteStack.Count - (paths.Count - 1); while (paths.Count > 1 && walkBackCurrentStackIndex >= 0) { if (paths[0] == localRouteStack[walkBackCurrentStackIndex]) { paths.RemoveAt(0); } else { break; } walkBackCurrentStackIndex++; } return(paths); } }