繁体   English   中英

为单页应用程序 (SPA) 创建链接以登陆不同的选项卡

[英]create a link for a single page application (SPA) to land on different tab

我正在使用 AngularJs 开发单页应用程序。 取决于用户选项,显示/隐藏相应的视图。

在此处输入图片说明

我的 URL 是localhost:8086/portal/ ,默认登录页面是 Dashboard。

但是,有一个要求:我不需要提供localhost:8086/portal/ ,而是需要在另一个页面上提供一个链接,例如localhost:8086/portal/reports ,默认情况下该链接应位于“报告”页面上。 因为,我正在开发 SPA,我的 URL 不会改变,但在这种情况下,我需要通过点击不同的链接来登陆具有不同登陆页面的相同 URL。

我的解决方案是使用 URL 重写,因此您仍会登陆 SPA 页面,但使用不同的 URL。 路由引擎将选择它并加载正确的模板。

.NET web.config 示例。

<rule name="NewsByEmail">
   <match url="^newsbyemail/" />
   <action type="Rewrite" url="/app/newsbyemail/index.html" />
</rule>

<rule name="NewsByEmailUnsubscribe">
   <match url="^newsbyemail/unsubscribe/" />
   <action type="Rewrite" url="/app/newsbyemail/index.html" />
</rule>

角度路由。

myApp.config(
    ($routeProvider, $locationProvider) => {
        $routeProvider
            .when("/newsbyemail/", {
                templateUrl: "app/newsbyemail/subscribe/subscribe.html"
            }).when("/newsbyemail/unsubscribe/", {
                templateUrl: "app/newsbyemail/unsubscribe/unsubscribe.html"
            });

        $locationProvider.html5Mode(true);
    }
);

暂无
暂无

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

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