将Angular [2] V3,Dart 1的路由转换为Angular 5,Dart 2

时间:2018-11-14 07:28:08

标签: angular dart angular-dart angular-dart-routing

我正忙于从Dart1迁移到Dart2,结果,我也不得不将Angular也从3升级到5。

我陷入了路由迁移中……

这是我们在Angular2中拥有的,与Angular3中相同:

@Component(
    ...
)
@RouteConfig(const [

    /*Meta*/
    const Route(path: "/home", component: AppHomeScene,
        name: SceneRoute.APP_HOME_SCENE, useAsDefault: true),
    const Route(path: "/project-home", component: ProjectHomeScene,
        name: SceneRoute.PROJECT_HOME_SCENE,),
    ...

])
class AppBuild implements AfterContentInit, OnDestroy {
    ...
}

在Angular5中,我删除了@RouteConfig块,创建了routes.dartpaths.dart

import 'package:angular_router/angular_router.dart';
import 'package:appbuild/enum/enums.dart';

class Paths {

    static final home = new RoutePath(path: "home", useAsDefault: true, additionalData: SceneRoute.APP_HOME_SCENE);

    ...
}

import 'package:appbuild/paths.dart';

export 'paths.dart';

class Routes {

    static final all = <RouteDefinition>[

        /*Meta*/
        RouteDefinition(routePath: Paths.home, component: AppHomeScene),

        ...
    ];
}

我目前有component: AppHomeScene的地方,文档说应该为hero_list_template.HeroListComponentNgFactory,

enter image description here

但是,如果我尝试执行导入,则IntelliJ会将其标记为错误:

import 'component/home/home-scene.template.dart' as 'home-scene-template';

enter image description here

在什么时候为我生成的模板能够进行这样的导入,或者我应该对HomeScene类做些什么才能使该模板可导入?

HomeScene只是仍然是Angular3格式的标准组件:

@Component(
    selector: 'home-scene',
    // language=CSS
    styles: const[""" 
        ...
    """
    ],
    // language=HTML
    template: """
        ...
    """,
    providers: const [...],
    directives: const [...]
)
class AppHomeScene extends AppScene implements AfterContentInit, OnDestroy {

    ....

}

1 个答案:

答案 0 :(得分:1)

在您的应用程序上运行首次构建后,将为每个具有模板的.dart文件创建template.dart文件。 IntelliJ在分析代码之前不知道要编译您的应用程序。

建议您构建应用程序,然后刷新分析结果。