簡體   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