Beispiel #1
0
        public RouterDataRoot CreateRoutes(string language = "en")
        {
            IBlazorItem rootItem = GetBlazorItemRootMock();

            RouterDataRoot routesData = new RouterDataRoot()
            {
                //Home
                Routes = new List <RouterData>()
                {
                    new RouterData()
                    {
                        Path = "/{Language}",
                        Page = PageComponent
                    }
                }
            };

            //Rest of menu items
            foreach (IBlazorItem item in rootItem.Children)
            {
                routesData.Routes.Add(new RouterData()
                {
                    Path     = "/{Language}" + item.Url.Substring(language.Length + 1),
                    Page     = PageComponent,
                    Children = item.HasChildren ? GetChildren(item) : null
                });
            }


            return(routesData);



            List <RouterData>?GetChildren(IBlazorItem blazorItem)
            {
                List <RouterData> children = new List <RouterData>();

                if (!blazorItem.HasChildren)
                {
                    return(null);
                }

                foreach (IBlazorItem child in blazorItem.Children)
                {
                    children.Add(new RouterData()
                    {
                        Path     = child.Url.Substring(child.Url.LastIndexOf('/')),
                        Page     = PageComponent,
                        Children = child.HasChildren ? GetChildren(child) : null
                    });
                }

                return(children);
            }
        }
        public RouterDataRoot ConfigRoutes(string language = "en")
        {
            ISitecoreItem rootItem = GetSitecoreItemRootMock();

            RouterDataRoot routesData = new RouterDataRoot()
            {
                //Home
                Routes = new List <RouterData>()
                {
                    new RouterData()
                    {
                        Path = "/{Language}",
                        Page = PageComponent
                    }
                }
            };

            //Rest of menu items
            foreach (ISitecoreItem item in rootItem.Children)
            {
                routesData.Routes.Add(new RouterData()
                {
                    Path     = "/{Language}" + item.Url.Substring(language.Length + 1),
                    Page     = PageComponent,
                    Children = item.HasChildren ? GetChildren(item) : null
                });
            }

            //Fallback error handling
            routesData.Routes.Add(new RouterData()
            {
                Path     = "/{Language}/{PageUrl}",
                Page     = PageComponent,
                Children = new List <RouterData>()
                {
                    new RouterData()
                    {
                        Path     = "/{ChildLevel1}",
                        Page     = PageComponent,
                        Children = new List <RouterData>()
                        {
                            new RouterData()
                            {
                                Path = "/{ChildLevel2}",
                                Page = PageComponent
                            }
                        }
                    }
                }
            });



            return(routesData);



            List <RouterData> GetChildren(ISitecoreItem sitecoreItem)
            {
                List <RouterData> children = new List <RouterData>();

                if (!sitecoreItem.HasChildren)
                {
                    return(null);
                }

                foreach (ISitecoreItem child in sitecoreItem.Children)
                {
                    children.Add(new RouterData()
                    {
                        Path     = child.Url.Substring(child.Url.LastIndexOf('/')),
                        Page     = PageComponent,
                        Children = child.HasChildren ? GetChildren(child) : null
                    });
                }

                return(children);
            }
        }