Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Latest commit

 

History

History
51 lines (35 loc) · 1.44 KB

Misc.md

File metadata and controls

51 lines (35 loc) · 1.44 KB

Using a Base URL

If all the URLs in your app are relative to some other "base" URL, use the basename option. This option transparently adds the given string to the front of all URLs you use.

const history = createHistory({
  basename: '/the/base'
});

history.listen(location => {
  console.log(location.pathname); // /home
});

history.push('/home'); // URL is now /the/base/home

Note: basename is not supported in createMemoryHistory.

Forcing Full Page Refreshes in createBrowserHistory

By default createBrowserHistory uses HTML5 pushState and replaceState to prevent reloading the entire page from the server while navigating around. If instead you would like to reload as the URL changes, use the forceRefresh option.

const history = createBrowserHistory({
  forceRefresh: true
});

Modifying the Hash Type in createHashHistory

By default createHashHistory uses a leading slash in hash-based URLs. You can use the hashType option to use a different hash formatting.

const history = createHashHistory({
  hashType: 'slash' // the default
});

history.push('/home'); // window.location.hash is #/home

const history = createHashHistory({
  hashType: 'noslash' // Omit the leading slash
});

history.push('/home'); // window.location.hash is #home

const history = createHashHistory({
  hashType: 'hashbang' // Google's legacy AJAX URL format
});

history.push('/home'); // window.location.hash is #!/home