Skip to content

Commit 5036ec2

Browse files
authored
Merge pull request #93 from Azzoo/#5-hashes-routing
Hash router integration
2 parents d145d72 + 82c573a commit 5036ec2

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

src/components/login/login.component.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import { RESTORE_PASSWORD_PAGE } from "../../root/root.constants.js";
1212

1313
import "./login.css";
1414

15+
import {
16+
HOME_PAGE
17+
} from "../../root/root.constants";
18+
1519
const authService = AuthService.getInstance();
1620

1721
class Login extends Component {
@@ -30,7 +34,7 @@ class Login extends Component {
3034
this.setState({
3135
loading: false,
3236
});
33-
history.replace("/home");
37+
history.replace(HOME_PAGE);
3438
})
3539
.catch((error) => {
3640
this.setState({

src/components/partials/custom-select/custom-select.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from "react";
22
import { withTranslation } from "react-i18next";
3-
3+
import { withRouter } from "react-router";
44
import history from "../../../root/root.history";
55

66
import { resetSearch } from "./../../../helpers/get-data";
@@ -24,21 +24,21 @@ class CustomSelect extends Component {
2424
};
2525

2626
setSelected = (option) => {
27-
const currentPath = history.location.pathname;
27+
const {currentPath} = this.props;
2828
const newPath = option === "All" ? "home" : option.toLowerCase();
2929

3030
if (`/${newPath}` !== currentPath) {
31-
history.replace(`/${newPath}`);
31+
history.push(`#/${newPath}`);
3232
}
3333
resetSearch();
3434

3535
this.setState({ selected: option });
3636
};
3737

38-
componentDidMount() {
39-
const currentLocation = history.location.pathname.match(/[a-zA-Z]+/g)[0];
38+
componentDidMount(){
39+
const {currentPath} = this.props;
4040
this.setState({
41-
selected: currentLocation === "home" ? "All" : currentLocation,
41+
selected: currentPath === "home" ? "All" : currentPath,
4242
});
4343
}
4444

@@ -73,4 +73,4 @@ class CustomSelect extends Component {
7373
}
7474
}
7575

76-
export default withTranslation("translation")(CustomSelect);
76+
export default withTranslation("translation")(withRouter(CustomSelect));

src/components/partials/search-panel/search-panel.component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class SearchPanel extends Component {
7171
onChange={this.setSearch}
7272
onFocus={() => this.setState({ isFocused: true })}
7373
></input>
74-
<CustomSelect />
74+
<CustomSelect currentPath="home" />
7575
</div>
7676
{isAutofill && !!value && (
7777
<Autofill

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from "react";
22
import ReactDOM from "react-dom";
3-
import { Router } from "react-router-dom";
3+
import { Router, HashRouter } from "react-router-dom";
44
import { renderRoutes } from "react-router-config";
55
import { I18nextProvider } from "react-i18next";
66
import i18next from "./helpers/i18n/index";
77

8-
import history from "./root/root.history";
8+
import hashHistory from "./root/root.history";
99
import routes from "./root/root.routes";
1010

1111
import * as serviceWorker from "./serviceWorker";
@@ -15,7 +15,7 @@ import "./styles/shared.css";
1515

1616
ReactDOM.render(
1717
<I18nextProvider i18n={i18next}>
18-
<Router history={history}>{renderRoutes(routes)}</Router>
18+
<HashRouter basename="/" history={hashHistory}>{renderRoutes(routes)}</HashRouter>
1919
</I18nextProvider>,
2020
document.getElementById("root")
2121
);

src/root/root.history.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBrowserHistory } from 'history';
1+
import { createHashHistory } from 'history';
22

3-
const history = createBrowserHistory();
4-
export default history;
3+
const history = createHashHistory();
4+
export default history;

src/root/root.routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const routes = [
9797
path: EDIT_BOARDING_PAGE,
9898
component: BoardingEditPage,
9999
exact: true,
100-
},
100+
},
101101
{
102102
path: NEW_BOARDING_PAGE,
103103
component: BoardingEditPage,

0 commit comments

Comments
 (0)