   # Replace existing state in the stack, do not reload
   replaceState: (state, title, url)->
     @_index = 0 if @_index < 0
-    url = URL.resolve(@_stack[@_index]?.url, url)
+    url = @_resolve(url)
     @_stack[@_index] = new Entry(this, url, { state: state, title: title, pop: true })
+
+  # Resolve URL based on current page URL.
+  _resolve: (url)->
+    if url
+      return URL.resolve(@_stack[@_index]?.url, url)
+    else # Yes, this could happen
+      return @_stack[@_index]?.url
 
   # Location uses this to move to a new URL.
   _assign: (url)->
-    url = URL.resolve(@_stack[@_index]?.url, url)
+    url = @_resolve(url)
     was = @_stack[@_index]?.url # before we destroy stack
     @_stack = @_stack[0..@_index]
     @_stack[++@_index] = new Entry(this, url)

  #
  # Push new state to the stack, do not reload
  pushState: (state, title, url)->
    url = URL.resolve(@_stack[@_index]?.url, url)
    @_stack[++@_index] = new Entry(this, url, { state: state, title: title, pop: true })

  # ### history.replaceState(state, title, url)


  # Location uses this to load new page without changing history.
  _replace: (url)->
    url = @_resolve(url)
    was = @_stack[@_index]?.url # before we destroy stack
    @_index = 0 if @_index < 0
    @_stack[@_index] = new Entry(this, url)
