# Zendesk 按钮在主题更改时未正确更新，无需刷新页面

**URL:** https://meta.discourse.org/t/zendesk-button-not-updating-correctly-on-topic-change-without-page-refresh/335896
**Category:** Support
**Tags:** zendesk
**Created:** [2024年十一月13日 04:26 UTC](https://meta.discourse.org/t/zendesk-button-not-updating-correctly-on-topic-change-without-page-refresh/335896 "2024-11-13T04:26:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![abinash.bhatta](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@abinash.bhatta](https://meta.discourse.org/u/abinash.bhatta)
#### Post date: [2024年十一月13日 04:26 UTC](https://meta.discourse.org/t/zendesk-button-not-updating-correctly-on-topic-change-without-page-refresh/335896/1 "2024-11-13T04:26:08Z")

</div>

您好，我在使用 Zendesk 插件的“在 Zendesk 上查看”按钮行为时遇到问题。当 Zendesk 中已存在工单时，该按钮会正确显示为“在 Zendesk 上查看”。但是，如果我导航到一个没有相应 Zendesk 工单的不同主题，该按钮最初仍显示为“在 Zendesk 上查看”，而不是“创建 Zendesk 工单”。刷新页面后，按钮会更新以显示正确的“创建 Zendesk 工单”选项。

 ![The image shows a screenshot of a website with a red arrow pointing to the "View on Zendesk" button. (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/1/4/a/14a588b7a2c31c7692a66714608bf0ecfdde5d7f.png)

似乎该按钮组件在导航到新主题时没有重新渲染。我认为解决方案可能涉及在页面更改时触发此组件的重新渲染。

有人能就如何最好地解决这个问题提出建议吗？或者是否有办法在导航时强制组件正确更新？任何见解或建议都将不胜感激。

---

<div class="post-metadata">

### Author: ![abinash.bhatta](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@abinash.bhatta](https://meta.discourse.org/u/abinash.bhatta)
#### Post date: [2024年十二月27日 03:30 UTC](https://meta.discourse.org/t/zendesk-button-not-updating-correctly-on-topic-change-without-page-refresh/335896/2 "2024-12-27T03:30:27Z")

</div>

您好！

希望您一切安好！我想跟进一下，看看这个问题是否有任何更新。您的见解或指导将不胜感激。

提前致谢！

---

<div class="post-metadata">

### Author: ![MihirR](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mihirr/32/475158_2.png) [@MihirR](https://meta.discourse.org/u/MihirR)
#### Post date: [2024年十二月27日 04:35 UTC](https://meta.discourse.org/t/zendesk-button-not-updating-correctly-on-topic-change-without-page-refresh/335896/3 "2024-12-27T04:35:30Z")

</div>

这可能是因为它没有检测到页面更改。这很可能是由于前端框架（可能是 Ember.js，因为 Discourse 使用它）在导航期间处理组件渲染的方式。

您可以添加一个路由更改的监听器，类似这样：

```import

export default Component.extend({
  router: service(),

  didInsertElement() {
    this._super(...arguments);

    this.router.on('routeDidChange', () => {
      this.refreshZendeskButton();
    });
  },

  willDestroyElement() {
    this._super(...arguments);

    this.router.off('routeDidChange', this.refreshZendeskButton);
  },
});

```

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [2024年十二月27日 05:55 UTC](https://meta.discourse.org/t/zendesk-button-not-updating-correctly-on-topic-change-without-page-refresh/335896/4 "2024-12-27T05:55:52Z")

</div>

这可能需要修改，因为它使用了 `setupComponent()`：

> <https://github.com/discourse/discourse-zendesk-plugin/blob/0d24cfa4aeedc224cb35749341b6188095701c5f/assets/javascripts/discourse-zendesk-plugin/connectors/after-topic-footer-buttons/zendesk-topic-actions.js>

检查是否存在有效的 zendesk 工单使用了 `zendesk_id`。也许它需要一个 `api.onPageChange()`？
