1

aureliaでRazor partials(cshtml)を使用する方法を示す非常に役立つ記事が見つかりました。しかし、私は実行するコードを得ることができなかったとRobEisenbergのコメントから学んだAureliaをカスタマイズして.cshtmlを使用する

は非難されました。彼は「あなたはViewLocatorサービスを使いたい」とコメントしました。私はgitHUbプロジェクトに続き、MVC5とRazor Partialsでの私の使用に直接関係しているのか分かりませんでした。だから私は混乱している。

これは一例ですが、私は私が代わりにindex.htmlのホーム/インデックス/ Index.cshtmlにルートオーレリアするために微調整することができ期待していたファイルをmain.js

import {LogManager} from "aurelia-framework"; 
import {ConsoleAppender} from "aurelia-logging-console"; 
import {ConventionalViewStrategy} from "aurelia-framework"; 

LogManager.addAppender(new ConsoleAppender()); 
LogManager.setLevel(LogManager.logLevel.debug); 

export function configure(aurelia) { 
aurelia.use 
    .standardConfiguration() 
    .developmentLogging(); 

ConventionalViewStrategy.convertModuleIdToViewUrl = function(moduleId){ 
    var moduleName = moduleId.replace("Scripts/", ""); 
    return `./Templates/${moduleName}`; 
} 


aurelia.start().then(a => a.setRoot("./Scripts/index", document.body)); 
} 

は、誰がどのように教えてもらえます.htmlテンプレートの代わりに.cshtmlを使用するMVC5プロジェクトでaureliaを設定するには?私は活字体とVS2015を使用しています

+0

をhttp://blog.nojaf.com/2015/05/06/using-razor-partials-cshtml- with-aurelia-components/main.jsのコードを入手した場所です。 http://www.gitterforum.com/discussion/aurelia-discuss?page=6884は、コードが廃止されたことを知ったところです –

答えて

2

私はちょうど成功しhttp://ilikekillnerds.com/2016/02/using-views-different-locations-aurelia/で述べたアプローチに続く:

import {Aurelia, ViewLocator, Origin, Container} from 'aurelia-framework'; 

export function configure(aurelia: Aurelia, container: Container) { 

    aurelia.use 
    .standardConfiguration() 
    .developmentLogging(); 

    ViewLocator.prototype.convertOriginToViewUrl = (origin: Origin) => { 
    var moduleId: string = origin.moduleId; 
    var moduleName = moduleId.split('/')[moduleId.split('/').length - 1].replace('ViewModel', 'View').replace('.js', '').replace('.ts', '');; 

    let newViewUrl = `./Templates/${moduleName}`; 
    console.log(newViewUrl); // e.g. ./Templates/app 

    return newViewUrl; 
    } 

    aurelia.start().then(() => aurelia.setRoot()); 
} 
+0

@BridgetArrington、それに試しましたか? –

+0

私はやった、それは動作しますが、私も使用しようとしているaureliaのプラグインのための経路変更を使用しているようです。私はそれが別の問題だと思う。 –

関連する問題