Skip to content

Commit 391fd33

Browse files
author
woodcutter
committed
feat(Fragment): add parsed params in redirect + switch push - replace
1 parent a99a677 commit 391fd33

File tree

4 files changed

+16
-5158
lines changed

4 files changed

+16
-5158
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ dist
4545
umd
4646

4747
.idea
48+
.DS_STORE
4849
package-lock.json

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-unity-router",
3-
"version": "1.4.1",
3+
"version": "1.5.0",
44
"description": "Redux router that syncs history with store",
55
"main": "dist/index.js",
66
"scripts": {

src/components/Fragment.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import BaseRouterComponent from './Base';
44
import { ID_DELIM, __DEV__} from '../constants';
5-
import { push as actionPush } from '../actions';
5+
import { replace } from '../actions';
66

77
class Fragment extends BaseRouterComponent {
88

@@ -41,24 +41,28 @@ class Fragment extends BaseRouterComponent {
4141

4242
if (!this.isSubscribed) return;
4343

44-
const routerStore = this.getStatefromStore();
4544
const { immutable, parseRoute } = this.router;
46-
const { redirect, push } = newProps || this.props;
45+
const { redirect } = newProps || this.props;
46+
4747
const current = this.current;
48+
const storeState = this.getStatefromStore();
49+
const routerStore = immutable ? storeState.toJS() : storeState;
4850

4951
if (routerStore) {
50-
const idPath = immutable ? routerStore.getIn([ 'route', 'idPath' ]) : routerStore.route.idPath;
52+
const idPath = routerStore.route.idPath;
53+
const params = routerStore.route.params;
54+
const query = routerStore.query;
55+
const hash = routerStore.hash;
5156
const routePath = idPath + ID_DELIM;
5257
const fragmentPath = current + ID_DELIM;
5358
const match = (routePath).indexOf(fragmentPath);
5459
const matchExact = routePath === fragmentPath;
5560

5661
if (matchExact && redirect) {
57-
return this.store.dispatch(push(
58-
typeof redirect === 'object' && redirect.id
59-
? parseRoute(redirect)
60-
: redirect
61-
));
62+
const redirectRoute = typeof redirect === 'object' && redirect.id ?
63+
parseRoute({ ...{ params, query, hash }, ...redirect }) : redirect;
64+
65+
return this.store.dispatch(replace(redirectRoute));
6266
}
6367

6468
if (match === 0 && !this.state.visible) {
@@ -101,10 +105,6 @@ Fragment.childContextTypes = {
101105
store: PropTypes.object
102106
};
103107

104-
Fragment.defaultProps = {
105-
push: actionPush
106-
};
107-
108108
if (__DEV__) {
109109
Fragment.propTypes = {
110110
id: PropTypes.oneOfType([
@@ -120,8 +120,7 @@ if (__DEV__) {
120120
redirect: PropTypes.oneOfType([
121121
PropTypes.object,
122122
PropTypes.string
123-
]),
124-
push: PropTypes.func.isRequired
123+
])
125124
};
126125
}
127126

0 commit comments

Comments
 (0)