1

aurelia で Razor パーシャル (cshtml) を使用する方法を示す非常に役立つ記事を見つけました。ただし、コードを実行することができず、RobEisenberg のコメントから次のことを学びました。

ConventionalViewStrategy.convertModuleIdToViewUrl 

廃止されていました。彼は「ViewLocator サービスを使用したい」とコメントしました。私は gitHUb プロジェクトをフォローしましたが、それが MVC5 と Razor Partials の使用に直接関連していることを確認できませんでした。だから私は混乱しています。

これは、aurelia を index.html ではなく Home/Index/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 を設定する方法を誰か教えてもらえますか? TypescriptとVS2015を使用しています

4

1 に答える 1

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());
}
于 2016-06-17T06:24:59.773 に答える