     @pendingIndex = -1
 
     @webContents.on 'navigation-entry-commited', (event, url) =>
-      if @pendingIndex >= 0  # Go to index.
-        @currentIndex = @pendingIndex
-        @pendingIndex = -1
-        @history[@currentIndex] = url
-      else  # Normal navigation.
+      if @pendingIndex is -1  # Normal navigation.
         @history = @history.slice 0, @currentIndex + 1  # Clear history.
         if @history[@currentIndex] isnt url
           @currentIndex++
           @history.push url
+      else  # Go to index.
+        @currentIndex = @pendingIndex
+        @pendingIndex = -1
+        @history[@currentIndex] = url
 
   loadUrl: (url, options={}) ->
     @pendingIndex = -1


  goBack: ->
    return unless @canGoBack()
    @pendingIndex = @currentIndex - 1
    @webContents._loadUrl @history[@pendingIndex], {}

  goForward: ->
    return unless @canGoForward()
    @pendingIndex = @currentIndex + 1
    @webContents._loadUrl @history[@pendingIndex], {}

  goToIndex: (index) ->

    @reload()

  canGoBack: ->
    @getActiveIndex() > 0

  canGoForward: ->
    @getActiveIndex() < @history.length - 1

  canGoToIndex: (index) ->
    index >=0 and index < @history.length
