Skip to content

Instantly share code, notes, and snippets.

@satnami
Last active August 30, 2021 10:05
Show Gist options
  • Save satnami/9b9f2ec06de5311b83f3216d7ec45a79 to your computer and use it in GitHub Desktop.
Save satnami/9b9f2ec06de5311b83f3216d7ec45a79 to your computer and use it in GitHub Desktop.
S3 routing with react routing
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { createBrowserHistory } from "history";
import configureStore from "./redux/configureStore";
import * as serviceWorker from "./serviceWorker";
import App from "./App";
import ErrorBoundary from "./pages/ErrorBoundary";
const store = configureStore();
const history = createBrowserHistory();
const root = document.getElementById("root");
if (root) {
// 1. Set up the browser history with the updated location (minus the # sign)
const path = (/#!(\/.*)$/.exec(window.location.hash) || [])[1];
if (path) {
history.replace(path);
}
// 2. Render our app
ReactDOM.render(
<ErrorBoundary>
<Provider store={store}>
<App />
</Provider>
</ErrorBoundary>,
root,
);
}
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
# Static website hosting
# Redirection rules with React Routing
[
{
"Condition": {
"HttpErrorCodeReturnedEquals": "404"
},
"Redirect": {
"HostName": "spa.satnami.xyz",
"ReplaceKeyPrefixWith": "#!/"
}
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment