# 我可以在 Glimmer 单文件组件中使用 routeAction 吗？

**URL:** <https://meta.discourse.org/t/can-i-use-routeaction-in-glimmer-single-file-components/288936>\
**Category:** Development\
**Created:** [2023 年12 月 16 日 22:03 UTC](https://meta.discourse.org/t/can-i-use-routeaction-in-glimmer-single-file-components/288936 "2023-12-16T22:03:38Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

作者： ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
发布日期： [2023 年12 月 18 日 13:02 UTC](https://meta.discourse.org/t/can-i-use-routeaction-in-glimmer-single-file-components/288936/7 "2023-12-18T13:02:18Z")

</div>

> [@Arkshine](#):
>
> `import { routeAction } from 'discourse/helpers/route-action';`
> 
> 它假设您在组件中定义了 `router` 服务。

我认为，如果您使用默认导出，它应该能按预期工作（即，无需注入路由服务，或手动传递对其的引用）

```js
import routeAction from "discourse/helpers/route-action";

```

（不确定为什么还有一个内部函数被导出为 `routeAction`……非常令人困惑！[让我们修复它](https://github.com/discourse/discourse/pull/24946)）

不过我想说……总的来说，我们正试图转向“闭包动作”，如 `{{on \"click\" this.someFunction}}`，而不是像 `{{action \"blah\"}}` 或 `{{routeAction \"blah\"}}` 这样的基于字符串的东西。

---

_[View the full topic](https://meta.discourse.org/t/can-i-use-routeaction-in-glimmer-single-file-components/288936)._
