2017-03-03 30 views
1

如果我有main.ts文件設置是這樣的...Aurelia多頁面應用程序?

Main.ts

import {Aurelia} from 'aurelia-framework' 
import environment from './environment'; 

//Configure Bluebird Promises. 
(<any>Promise).config({ 
    warnings: { 
    wForgottenReturn: false 
    } 
}); 

export function configure(aurelia: Aurelia) { 
    aurelia.use 
    .standardConfiguration() 
    .feature('resources'); 

    if (environment.debug) { 
    aurelia.use.developmentLogging(); 
    } 

    if (environment.testing) { 
    aurelia.use.plugin('aurelia-testing'); 
    } 



    // PLAYING AROUND - Log to Console the Value of ShowLanding Session Storage 
    let showLanding = false; 
    console.log(showLanding); 
    // let showLanding = sessionStorage.getItem("show_landing"); 

    if (showLanding || showLanding === null) { 
    aurelia.start().then(() => aurelia.setRoot('landing')); 
    } else { 
    aurelia.start().then(() => aurelia.setRoot('blog/blog')); 
    } 
} 

我在我的應用程序的根目錄 「landing.html上/ .TS」 文件,這段代碼看起來很好。意思是,如果「showLanding = false」,應用程序將加載到我的「blog.html」頁面,如果它是真的,它將加載到我的「Landing.html」頁面。

我想要做的是創建一個管理頁面。隨時訪問URL「.... com/admin」帶我到「admin.html」頁面我已設置。

是否有可能做前端?我知道的其他方式是從服務器路由匹配URL和靜態服務,是嗎?

+1

要清楚,你真的需要有不同的根源嗎?你不能只使用內置路由器嗎?請參閱Hub文檔:http://aurelia.io/hub.html#/doc/article/aurelia/router/latest/router-configuration/ – kettch

+0

請查看推送狀態詳細信息部分:http://aurelia.io /hub.html#/doc/article/aurelia/router/latest/router-configuration/1這將允許你有foo.com/admin而不是foo.com/#/admin –

+0

這就是我所配置的,但不是加工。文檔說我需要「服務器端配置」,但沒有詳細說明,我不確定那裏需要做什麼。我會考慮,如果我以... /#/ admin或.../admin的方式啓動/關閉推送狀態,它應該導航到該頁面,但是我的管理頁面只是在路由器視圖所在的位置。我如何才能導航到管理視圖? –

回答

0

通過簡單閱讀window.location.pathname並將我的管理頁面設置爲應用程序根目錄,我設法讓它工作(我希望它工作的方式)。

so my Main.ts was changed to: 

    ... 

    if (showLanding || showLanding === null) { 
    aurelia.start().then(() => aurelia.setRoot('landing')); 
    } else if (window.location.pathname == "/admin") { 
    aurelia.start().then(() => aurelia.setRoot('admin/admin')); 
    } else { 
    aurelia.start().then(() => aurelia.setRoot('blog/blog')); 
    } 
} 

我敢肯定,這可能不是完成這一任務的最好方式,但它似乎是工作現在。如果遇到任何問題,我肯定會更新。

此外,如果其他人想要與任何其他想法,關注,建議或反饋意見,請做!謝謝!