Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How work with local site version without server? #3943

Closed
Slavenin opened this issue Sep 26, 2016 · 4 comments
Closed

How work with local site version without server? #3943

Slavenin opened this issue Sep 26, 2016 · 4 comments

Comments

@Slavenin
Copy link

Hi!
I try use react router with local version app after build them. Browser open file as link

file://app/dir/index.html

But router throw 404 error. How i can setting up router fo work with local version site?
repo
Tnx!

@timdorr
Copy link
Member

timdorr commented Sep 26, 2016

You have to use a hash history to use a local file. Browser histories don't work without a server.

@timdorr timdorr closed this as completed Sep 26, 2016
@tomprogers
Copy link

I don't think this will work.

Although it's possible to create routing configuration that enables the index route to load when the app is served over the file:// protocol, navigation around the app breaks down immediately.

The reason navigation fails is that react-router -- like many single-page-app routing modules -- is ultimately built on top of the Web History API. The Web History API is implemented natively in browsers, and it cares about document.origin (a read-only property that is specially set to null when viewing a page loaded over the file:// protocol). Core History methods apparently throw exceptions when invoked within documents whose origin is null, which prevents react-router from actually carrying out navigation changes. This problem seems to apply whether the router is configured with a browserHistory or a hashHistory; a fatal exception is thrown when pushState is invoked on history.

@timdorr
Copy link
Member

timdorr commented Jan 10, 2017

You can use a hash history on a local file just fine. We use it in our test suite. Make sure you've configured things correctly.

@Slavenin
Copy link
Author

@tomprogers, i use hashHistory and this work fine

@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants