如何在 dart 的 angular2-beta.20 中为路由器使用 HashLocationStrategy? [英] How to use HashLocationStrategy for router in angular2-beta.20 in dart?

查看:24
本文介绍了如何在 dart 的 angular2-beta.20 中为路由器使用 HashLocationStrategy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 Dart 的 angular2-beta.20 中使用带有 HashLocationStrategy 的路由器.但我找不到任何文档,除了此链接指向 angular2-beta.15 个文档,这是不完整的.该示例显示了 TypeScript 导入而不是 Dart 导入.

I tried to use the router in angular2-beta.20 in Dart with the HashLocationStrategy. But I couldn't find any docs, except for this link to angular2-beta.15 docs, which are incomplete. The example shows TypeScript imports instead of Dart ones.

所以我尝试导入package:angular2/router.dart,但Dart Analyzer一直抱怨找不到LocationStrategyHashLocationStrategy>

So I tried to import package:angular2/router.dart, but the Dart Analyzer keeps complaining that it can not find LocationStrategy and HashLocationStrategy

我也不知道如何准确地编写导入,因为顶级提供函数,如上例所示,似乎不存在.provide(LocationStrategy, {useClass: HashLocationStrategy})

Also I don't know, how to write the import exactly, because a top-level provide function, as in the example above, seems non existent. provide(LocationStrategy, {useClass: HashLocationStrategy})

推荐答案

经过一番研究,我发现了以下内容:

After some research I found the following:

  • LocationStrategyHashLocationStrategy 现在是package:angular2/platform/common.dart 而不是 package:angular2/router.dart.

  • LocationStrategy and HashLocationStrategy are now part of package:angular2/platform/common.dart instead of package:angular2/router.dart.

bootstrap()- 方法是平台特定的,所以我们需要导入package:angular2/platform/browser.dart.

The bootstrap()- method is platform specific, so we need to import package:angular2/platform/browser.dart.

我们需要导入 package:angular2/router.dart 以使 ROUTER_PROVIDERSbootstrap() 方法中可用.p>

We need to import package:angular2/router.dart to have ROUTER_PROVIDERS available in bootstrap() method.

这是一个用于初始化 dart 文件的工作代码示例:

Here is a working code example for the dart file initializing :

// needed to import "bootstrap" method
import 'package:angular2/platform/browser.dart';

// needed to import LocationStrategy and HashLocationStrategy
import 'package:angular2/platform/common.dart';

// needed for Provider class
import 'package:angular2/angular2.dart';

// needed to import ROUTER_PROVIDERS
import 'package:angular2/router.dart'; 

// import your app_component as root component for angular2
import 'app_component.dart';

void main() {
  bootstrap(AppComponent, [
    ROUTER_PROVIDERS,
    const Provider(LocationStrategy, useClass: HashLocationStrategy)
  ]);
}

希望这对某人有所帮助!:)

Hope this helps somebody! :)

这篇关于如何在 dart 的 angular2-beta.20 中为路由器使用 HashLocationStrategy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆