在 Aurelia 对话框中,如何为 viewModel 创建路由?

In an Aurelia Dialog, how to create routes for the viewModel?

打开 Aurelia 对话框时,您通常会向它传递一个 viewModel。

这就是我目前的做法,但如果路径不在此处进行硬编码会更好。

            let lookupResponse = await this.dialogService.open(
            {
                model:
                {
                    configuration: this.LookupConfiguration
                    caption: 'Select an item'
                },
                viewModel: 'App/Components/Lookup/LookupDialog'
            });

我宁愿能够像路由一样引用 viewModel 路径

            let lookupResponse = await this.dialogService.open(
            {
                model:
                {
                    configuration: this.LookupConfiguration
                    caption: 'Select an item'
                },
                viewModel: App.routes.components.lookupdialog
            });

如果您只是为组件添加一个 Routes.js 并尝试使用它,您会收到此错误:

Uncaught (in promise) Error: Cannot determine default view strategy for object.

那么需要添加什么才能让它起作用?某种自定义视图策略?

您可以 import 将对话框添加到您的 class 中并像这样使用它们:

import { LookupDialog } from "app/components/lookup/lookup-dialog.ts";

export class Foo {
  bar() {
    let lookupResponse = await this.dialogService.open(
       {
         model:
         {
           configuration: this.LookupConfiguration
           caption: 'Select an item'
         },
         viewModel: LookupDialog
       });
  }
}