简体   繁体   English

AngularJs中具有嵌套ui视图的不错的URL

[英]decent Url with nested ui-view in AngularJs

We all know Angular is a SPA (Single Page Application). 我们都知道Angular是SPA(单页应用程序)。 i want to know the proper solution where i can show the one main left side menu selector page and when a user click anything from menu it should be in right side view div. 我想知道适当的解决方案,在哪里可以显示一个主左侧菜单选择器页面,并且当用户单击菜单中的任何内容时,它应该在右侧视图div中。

i have it and implemented like this. 我有它,像这样实现。

  $stateProvider
        .state('home', {
           url: '/',
           cache: false,
           templateUrl : 'resources/components/home/home.html',
            controller : 'homeController',

         }).state('main', {
            url: '/main',
           templateUrl : 'resources/components/dashboard/main.html',
            controller : 'dashboardController',


        }).state('main.profile', {
            url: '/profile',
           templateUrl : 'resources/components/clinicprofile/profile.html',
            controller : 'profileController',

my methode is exactly working like this... 我的方法正像这样工作...

at the very first page /# i am showing login page and when a user is login he redirects to #/main where only left menu bar is showing, and when user proceed with profile page the url become like #/main/profile because of ui view in main.html so that main.html can consist all other view in it (profile.,setting.html etc) 在第一页/#我正在显示登录页面,当用户登录时,他重定向到#/ main,其中仅显示左侧菜单栏,并且当用户继续使用个人资料页面时,URL会像#/ main / profile一样,原因是ui视图在main.html中,以便main.html可以包含其中的所有其他视图(profile。,setting.html等)

what i want is when a user login he should be redirected to /profile and profile page will be there with left column.. again if a user click on setting from left menu bar he should be redirect to /setting but in this case i have to reload the whole page and main.html content will be in each page.. then again what is the point to SPA if i am giving each page a full content like header footer left menu bar... is there any solution where the left column will be there and user can enjoy a decent url like /profile, /setting, and not /main/profile, main/setting. 我想要的是当用户登录时应该将他重定向到/ profile,并且配置文件页面将在左列..再次,如果用户单击左侧菜单栏中的设置,则应该将其重定向到/ setting,但是在这种情况下,我有重新加载整个页面,并且main.html内容将在每个页面中..如果我为每个页面提供完整的内容(如页眉页脚左侧菜单栏),那么SPA的意义何在?列将在那里,用户可以享受一个不错的网址,例如/ profile,/ setting,而不是/ main / profile,main / setting。

i hope you got my question. 我希望你能回答我的问题。

Yes, you can define separate views for the side menu, main menu, adds etc and reuse them. 是的,您可以为侧面菜单,主菜单,添加等定义单独的视图,然后重新使用它们。 For example you can create sidemenu.html and put it in resources/components/dashboard and then reuse it for both main and main.profile states. 例如,您可以创建sidemenu.html并将其放在resources / components / dashboard中,然后将其重新用于main和main.profile状态。

 $stateProvider
        .state('home', {
           url: '/',
           cache: false,
           templateUrl : 'resources/components/home/home.html',
            controller : 'homeController',

         }).state('main', {
            url: '/main',
            views: {
                '': {
                    templateUrl : 'resources/components/dashboard/main.html',
                    controller : 'dashboardController',
                },

                'nav@main': {
                    templateUrl : 'resources/components/dashboard/sidemenu.html'
                }
            }

        }).state('profile', {
            url: '/profile',
            views: {
                '': {
                    templateUrl : 'resources/components/clinicprofile/profile.html',
                    controller : 'profileController',
                },

                'nav@main.profile': {
                    templateUrl : 'resources/components/dashboard/sidemenu.html'
                }
            }
        });

And in index.html you cand have something like this: 在index.html中,您可以输入以下内容:

<div ui-view></div>
<div ui-view="nav"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM