<commit_before>/* @flow */

import type VueRouter from '../index'
import { History } from './base'

export class AbstractHistory extends History {
  index: number;
  stack: Array<Route>;

  constructor (router: VueRouter) {
    super(router)
    this.stack = []
    this.index = 0
  }

  push (location: RawLocation) {
    this.transitionTo(location, route => {
      this.stack = this.stack.slice(0, this.index + 1).concat(route)
      this.index++
    })
  }

  replace (location: RawLocation) {
    this.transitionTo(location, route => {
      this.stack = this.stack.slice(0, this.index).concat(route)
    })
  }

  go (n: number) {
    const targetIndex = this.index + n
    if (targetIndex < 0 || targetIndex >= this.stack.length) {
      return
    }
    const location = this.stack[targetIndex]
    this.confirmTransition(location, () => {
      this.index = targetIndex
      this.updateRoute(location)
    })
  }

  ensureURL () {
    // noop
  }
}<commit_msg>fix abstract history go() (fix #726)<commit_after>/* @flow */

import type VueRouter from '../index'
import { History } from './base'

export class AbstractHistory extends History {
  index: number;
  stack: Array<Route>;

  constructor (router: VueRouter) {
    super(router)
    this.stack = []
    this.index = -1
  }

  push (location: RawLocation) {
    this.transitionTo(location, route => {
      this.stack = this.stack.slice(0, this.index + 1).concat(route)
      this.index++
    })
  }

  replace (location: RawLocation) {
    this.transitionTo(location, route => {
      this.stack = this.stack.slice(0, this.index).concat(route)
    })
  }

  go (n: number) {
    const targetIndex = this.index + n
    if (targetIndex < 0 || targetIndex >= this.stack.length) {
      return
    }
    const route = this.stack[targetIndex]
    this.confirmTransition(route, () => {
      this.index = targetIndex
      this.updateRoute(route)
    })
  }

  ensureURL () {
    // noop
  }
}
{'fraction_non_alphanumeric': 0.1421994884910486, 'fraction_numerical': 0.006649616368286445, 'mean_word_length': 2.6836158192090394, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4003282', 'n_tokens_mistral': 638, 'n_tokens_neox': 618, 'n_words': 139}