title: Angular 5 : Failed to execute 'replaceState' on 'History': A history state object with URL cannot be created in a document with origin 'null'
body: <p>On build --prod of my app I get this error when loading the index.html from a root dir or when hosted by a server :</p>
  
  <pre><code>ERROR Error: Uncaught (in promise): SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///G:/#/' cannot be created in a document with origin 'null' and URL 'file:///G:/index.html'.
  Error: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///G:/#/' cannot be created in a document with origin 'null' and URL 'file:///G:/index.html'.
      at e.replaceState (vendor.7c715405490dfd9b75c0.bundle.js:1)
      at e.replaceState (vendor.7c715405490dfd9b75c0.bundle.js:1)
      at t.replaceState (vendor.7c715405490dfd9b75c0.bundle.js:1)
      at t.resetUrlToCurrentUrlTree (vendor.7c715405490dfd9b75c0.bundle.js:1)
      at t.resetStateAndUrl (vendor.7c715405490dfd9b75c0.bundle.js:1)
      at vendor.7c715405490dfd9b75c0.bundle.js:1
      at t.invoke (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
      at Object.onInvoke (vendor.7c715405490dfd9b75c0.bundle.js:1)
      at t.invoke (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
      at e.run (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
      at e.replaceState (vendor.7c715405490dfd9b75c0.bundle.js:1)
      at e.replaceState (vendor.7c715405490dfd9b75c0.bundle.js:1)
      at t.replaceState (vendor.7c715405490dfd9b75c0.bundle.js:1)
      at t.resetUrlToCurrentUrlTree (vendor.7c715405490dfd9b75c0.bundle.js:1)
      at t.resetStateAndUrl (vendor.7c715405490dfd9b75c0.bundle.js:1)
      at vendor.7c715405490dfd9b75c0.bundle.js:1
      at t.invoke (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
      at Object.onInvoke (vendor.7c715405490dfd9b75c0.bundle.js:1)
      at t.invoke (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
      at e.run (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
      at P (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
      at polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
      at t.invokeTask (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
      at Object.onInvokeTask (vendor.7c715405490dfd9b75c0.bundle.js:1)
      at t.invokeTask (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
      at e.runTask (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
      at v (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
      at &lt;anonymous&gt;
  kt @ vendor.7c715405490dfd9b75c0.bundle.js:1
  t.handleError @ vendor.7c715405490dfd9b75c0.bundle.js:1
  next @ vendor.7c715405490dfd9b75c0.bundle.js:1
  e.object.i @ vendor.7c715405490dfd9b75c0.bundle.js:1
  e.__tryOrUnsub @ vendor.7c715405490dfd9b75c0.bundle.js:1
  e.next @ vendor.7c715405490dfd9b75c0.bundle.js:1
  e._next @ vendor.7c715405490dfd9b75c0.bundle.js:1
  e.next @ vendor.7c715405490dfd9b75c0.bundle.js:1
  e.next @ vendor.7c715405490dfd9b75c0.bundle.js:1
  e.emit @ vendor.7c715405490dfd9b75c0.bundle.js:1
  (anonymous) @ vendor.7c715405490dfd9b75c0.bundle.js:1
  t.invoke @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
  e.run @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
  t.runOutsideAngular @ vendor.7c715405490dfd9b75c0.bundle.js:1
  onHandleError @ vendor.7c715405490dfd9b75c0.bundle.js:1
  t.handleError @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
  e.runGuarded @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
  t @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
  n.microtaskDrainDone @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
  v @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
  Promise.then (async)
  d @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
  t.scheduleTask @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
  e.scheduleTask @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
  e.scheduleMicroTask @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
  O @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
  t.then @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
  t.bootstrapModule @ vendor.7c715405490dfd9b75c0.bundle.js:1
  x35b @ main.991a69005f6003446625.bundle.js:1
  t @ inline.31e1fb380eb7cf3d75b1.bundle.js:1
  0 @ main.991a69005f6003446625.bundle.js:1
  t @ inline.31e1fb380eb7cf3d75b1.bundle.js:1
  window.webpackJsonp @ inline.31e1fb380eb7cf3d75b1.bundle.js:1
  (anonymous) @ main.991a69005f6003446625.bundle.js:1
  </code></pre>
  
  <p>I don't understand this because even when I open index.html and manually edit it 
  here :  <code>&lt;script&gt;document.write('&lt;base href="./" /&gt;')</code> and here <code>&lt;base href="./"&gt;</code> the error persists.</p>
  
  <p>please give me a guide to avoid this sort of error.</p>