# Wie ändere ich den Link, der mit einer Schaltfläche im Benutzer-Menüfeld verknüpft ist

**URL:** https://meta.discourse.org/t/how-to-change-the-link-associated-with-a-button-in-the-user-menu-panel/181911
**Category:** Development
**Created:** [3. März 2021 um 20:09 UTC](https://meta.discourse.org/t/how-to-change-the-link-associated-with-a-button-in-the-user-menu-panel/181911 "2021-03-03T20:09:11Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![MrDavis97](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mrdavis97/32/206391_2.png) [@MrDavis97](https://meta.discourse.org/u/MrDavis97)
#### Post date: [3. März 2021 um 20:09 UTC](https://meta.discourse.org/t/how-to-change-the-link-associated-with-a-button-in-the-user-menu-panel/181911/1 "2021-03-03T20:09:11Z")

</div>

Anstatt dass der hervorgehobene Button auf `u/miles/summary` verweist, möchte ich, dass er auf `u/miles/activity` zeigt. Wie kann ich das umsetzen? Ich habe online danach gesucht (es scheint, dass man das `data-url`-Attribut mit JavaScript ändern muss, aber die einzige Methode, die ich gefunden habe, erfordert zunächst die ID des Elements zu ermitteln, welche dieses Element jedoch nicht besitzt.)

 ![PIC](https://global.discourse-cdn.com/meta/original/3X/b/d/bd77a7b38b082144f0bf12a5c3fd2394204742f9.png)

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [3. März 2021 um 23:22 UTC](https://meta.discourse.org/t/how-to-change-the-link-associated-with-a-button-in-the-user-menu-panel/181911/2 "2021-03-03T23:22:11Z")

</div>

Sie müssten das betreffende Widget in einer Theme-Komponente erneut öffnen, ähnlich wie hier:

```plaintext
api.reopenWidget("user-menu-links", {
  profileGlyph() {
    return {
      title: Titles["profile"],
      className: "user-preferences-link menu-link",
      id: QuickAccess.PROFILE,
      icon: "user",
      action: UserMenuAction.QUICK_ACCESS,
      actionParam: QuickAccess.PROFILE,
      data: { url: `${this.attrs.path}/activity` },
      role: "tab",
      tabAttrs: this._tabAttrs(QuickAccess.PROFILE),
    };
  },
})

```

---

<div class="post-metadata">

### Author: ![MrDavis97](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mrdavis97/32/206391_2.png) [@MrDavis97](https://meta.discourse.org/u/MrDavis97)
#### Post date: [3. März 2021 um 23:31 UTC](https://meta.discourse.org/t/how-to-change-the-link-associated-with-a-button-in-the-user-menu-panel/181911/3 "2021-03-03T23:31:12Z")

</div>

Danke! Das ergibt Sinn, denke ich.  
Eine Sache jedoch: Ich füge dies in `<head>` ein, erhalte aber den Fehler: `SyntaxError: unknown: Unexpected token, expected "," (28:6)`

```
<script type="text/discourse-plugin" version="0.8">    
    api.reopenWidget("user-menu-links", {
      profileGlyph() {
        return {
          title: Titles["profile"],
          className: "user-preferences-link menu-link",
          id: QuickAccess.PROFILE,
          icon: "user",
          action: UserMenuAction.QUICK_ACCESS,
          actionParam: QuickAccess.PROFILE,
          data: { url: `${this.attrs.path}/activity` },
          role: "tab",
          tabAttrs: this._tabAttrs(QuickAccess.PROFILE),
        };
      },
    }
</script>

```

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [3. März 2021 um 23:36 UTC](https://meta.discourse.org/t/how-to-change-the-link-associated-with-a-button-in-the-user-menu-panel/181911/4 "2021-03-03T23:36:58Z")

</div>

Oben fehlte eine schließende Klammer, aktualisiert

---

<div class="post-metadata">

### Author: ![MrDavis97](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mrdavis97/32/206391_2.png) [@MrDavis97](https://meta.discourse.org/u/MrDavis97)
#### Post date: [4. März 2021 um 02:33 UTC](https://meta.discourse.org/t/how-to-change-the-link-associated-with-a-button-in-the-user-menu-panel/181911/6 "2021-03-04T02:33:48Z")

</div>

Kein Fehler mehr, aber… Jetzt öffnet sich das Dropdown-Menü „Benutzer-Menü-Links

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [4. März 2021 um 10:33 UTC](https://meta.discourse.org/t/how-to-change-the-link-associated-with-a-button-in-the-user-menu-panel/181911/7 "2021-03-04T10:33:22Z")

</div>

Was hast du getan, um es zu debuggen?

Ein Blick in die JavaScript-Konsole im Browser ist immer ein guter Anfang.

Wenn du hinschaust, gibt es drei offensichtliche Probleme (letztendlich).

Die Lösung ist in diesem Fall ziemlich einfach: Du musst lediglich die fehlenden Konstanten bereitstellen:

```plaintext
      const UserMenuAction = {
        QUICK_ACCESS: "quickAccess",
      };

      const QuickAccess = {
        BOOKMARKS: "bookmarks",
        MESSAGES: "messages",
        NOTIFICATIONS: "notifications",
        PROFILE: "profile",
      };
      
      const Titles = {
        bookmarks: "user.bookmarks",
        messages: "user.private_messages",
        notifications: "user.notifications",
        profile: "user.preferences",
      };

```

Sobald du diese (aus dem ursprünglichen Quellcode) hinzufügst, funktioniert es 🎉

(Aber siehe Faizaans Optimierung unten, die diese überflüssig macht – das ist noch besser :))

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [4. März 2021 um 10:58 UTC](https://meta.discourse.org/t/how-to-change-the-link-associated-with-a-button-in-the-user-menu-panel/181911/8 "2021-03-04T10:58:08Z")

</div>

Einfacher ausgedrückt

```
<script type="text/discourse-plugin" version="0.8">    
api.reopenWidget("user-menu-links", {
  profileGlyph() {
   const glyph = this._super(...arguments);
   glyph['data'] = { url: `${this.attrs.path}/activity` };
   return glyph;
  },
}

```

Noch nicht getestet 😉

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [4. März 2021 um 11:07 UTC](https://meta.discourse.org/t/how-to-change-the-link-associated-with-a-button-in-the-user-menu-panel/181911/9 "2021-03-04T11:07:19Z")

</div>

Ja, viel besser und vermeidet die Notwendigkeit von Konstanten – schöne Optimierung! 🙂

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [4. März 2021 um 12:30 UTC](https://meta.discourse.org/t/how-to-change-the-link-associated-with-a-button-in-the-user-menu-panel/181911/10 "2021-03-04T12:30:34Z")

</div>

> [@fzngagan](#):
>
> `...arguments`

Tatsächlich können Sie noch einen Schritt weitergehen und das weglassen:

```plaintext
      api.reopenWidget("user-menu-links", {
        profileGlyph() {
         const glyph = this._super();
         glyph['data'] = { url: `${this.attrs.path}/activity` };
         return glyph;
        }
      });

```

Da keine Argumente vorhanden sind.

---

<div class="post-metadata">

### Author: ![MrDavis97](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mrdavis97/32/206391_2.png) [@MrDavis97](https://meta.discourse.org/u/MrDavis97)
#### Post date: [4. März 2021 um 22:50 UTC](https://meta.discourse.org/t/how-to-change-the-link-associated-with-a-button-in-the-user-menu-panel/181911/11 "2021-03-04T22:50:15Z")

</div>

Danke, Leute! Funktioniert einwandfrei. Ich lerne auch viel über das Bearbeiten von Discourse!
