Forward query arguments during redirect (#990)

* Transfer query arguments over with routing.

* Create a Query Redirect wrapper.

* Add RedirectWithQuery component to SendTransaction index redirect.

* Correct hash-query ordering.
This commit is contained in:
aitrean 2018-02-08 23:02:56 -05:00 committed by Daniel Ternyak
parent eaa9ac392c
commit 626afe554a
3 changed files with 36 additions and 8 deletions

View File

@ -17,6 +17,7 @@ import { Store } from 'redux';
import { pollOfflineStatus } from 'actions/config';
import { AppState } from 'reducers';
import { RouteNotFound } from 'components/RouteNotFound';
import { RedirectWithQuery } from 'components/RedirectWithQuery';
import 'what-input';
interface Props {
@ -94,14 +95,15 @@ export default class Root extends Component<Props, State> {
const LegacyRoutes = withRouter(props => {
const { history } = props;
const { pathname, hash } = props.location;
const { pathname } = props.location;
let { hash } = props.location;
if (pathname === '/') {
hash = hash.split('?')[0];
switch (hash) {
case '#send-transaction':
case '#offline-transaction':
history.push('/send-transaction');
break;
return <RedirectWithQuery from={pathname} to={'account/send'} />;
case '#generate-wallet':
history.push('/');
break;
@ -125,9 +127,9 @@ const LegacyRoutes = withRouter(props => {
return (
<Switch>
<Redirect from="/signmsg.html" to="/sign-and-verify-message" />
<Redirect from="/helpers.html" to="/helpers" />
<Redirect from="/send-transaction" to="/account/send" />
<RedirectWithQuery from="/signmsg.html" to="/sign-and-verify-message" />
<RedirectWithQuery from="/helpers.html" to="/helpers" />
<RedirectWithQuery from="/send-transaction" to={'/account/send'} />
</Switch>
);
});

View File

@ -0,0 +1,25 @@
import React from 'react';
import { Redirect } from 'react-router';
interface RouterProps {
from: string;
to: string;
strictArg?: boolean;
exactArg?: boolean;
pushArg?: boolean;
}
export class RedirectWithQuery extends React.Component<RouterProps> {
public render() {
const { from, to, strictArg, exactArg, pushArg } = this.props;
return (
<Redirect
from={from}
to={{ pathname: to, search: window.location.search }}
strict={strictArg}
exact={exactArg}
push={pushArg}
/>
);
}
}

View File

@ -6,7 +6,8 @@ import { UnlockHeader } from 'components/ui';
import { SideBar } from './components/index';
import { getWalletInst } from 'selectors/wallet';
import { AppState } from 'reducers';
import { RouteComponentProps, Route, Switch, Redirect } from 'react-router';
import { RouteComponentProps, Route, Switch } from 'react-router';
import { RedirectWithQuery } from 'components/RedirectWithQuery';
import {
WalletInfo,
RequestPayment,
@ -68,7 +69,7 @@ class SendTransaction extends React.Component<Props> {
exact={true}
path={currentPath}
render={() => (
<Redirect
<RedirectWithQuery
from={`${currentPath}`}
to={`${wallet.isReadOnly ? `${currentPath}/info` : `${currentPath}/send`}`}
/>