# Making ‘previous/next topic’ keyboard shortcuts into a theme component

**URL:** <https://meta.discourse.org/t/making-previous-next-topic-keyboard-shortcuts-into-a-theme-component/287314>\
**Category:** Development\
**Created:** [December 2, 2023, 9:27pm UTC](https://meta.discourse.org/t/making-previous-next-topic-keyboard-shortcuts-into-a-theme-component/287314 "2023-12-02T21:27:43Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![denvergeeks](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denvergeeks/32/327671_2.png) [@denvergeeks](https://meta.discourse.org/u/denvergeeks)\
**Post date:** [December 3, 2023, 7:31am UTC](https://meta.discourse.org/t/making-previous-next-topic-keyboard-shortcuts-into-a-theme-component/287314/3 "2023-12-03T07:31:27Z")

</div>

Thank you, @merefield! I am stuck (at least I think that’s where 🤓 ) at the javascript snippet for the back button…

[discourse-tc-topic-next-button/javascripts/discourse/components/topic-previous-button.js at master · denvergeeks/discourse-tc-topic-next-button · GitHub](https://github.com/denvergeeks/discourse-tc-topic-next-button/blob/master/javascripts/discourse/components/topic-previous-button.js) where at the moment I have this…

```plaintext
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import {
  nextTopicUrl,
  previousTopicUrl,
} from "discourse/lib/topic-list-tracker";
import DiscourseURL from "discourse/lib/url";
import { inject as service } from "@ember/service";

export default class TopicPreviousButton extends Component {
  @service site;
  @tracked label = "";
  @tracked showButton = false;
  @tracked lastURL = "";

  constructor(owner, args) {
    super(owner, args);
    previousTopicUrl().then((url) => {
      if (url) {
        this.showButton = true;
        this.lastURL = url;
      } else {
        this.showButton = false;
        this.lastURL = "";
      }
    })
  };

  get goFirst() {
    return settings.topic_next_always_go_to_first_post
  }

  @action
  goToPreviousTopic() {
    let url;
    if (this.lastURL) {
      url = this.goFirst
        ? this.lastURL.substring(0, this.lastURL.nextIndexOf("/"))
        : this.lastURL;
      DiscourseURL.routeTo(url);
    }
  };
}

```

I think the problem is near the bottom at

```plaintext
? this.lastURL.substring(0, this.lastURL.nextIndexOf("/"))

```

Any thoughts?

I tried

```plaintext
? this.lastURL.substring(0, this.lastURL.indexOf("/"))

```

---

_[View the full topic](https://meta.discourse.org/t/making-previous-next-topic-keyboard-shortcuts-into-a-theme-component/287314)._
