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 { pollOfflineStatus } from 'actions/config';
import { AppState } from 'reducers'; import { AppState } from 'reducers';
import { RouteNotFound } from 'components/RouteNotFound'; import { RouteNotFound } from 'components/RouteNotFound';
import { RedirectWithQuery } from 'components/RedirectWithQuery';
import 'what-input'; import 'what-input';
interface Props { interface Props {
@ -94,14 +95,15 @@ export default class Root extends Component<Props, State> {
const LegacyRoutes = withRouter(props => { const LegacyRoutes = withRouter(props => {
const { history } = props; const { history } = props;
const { pathname, hash } = props.location; const { pathname } = props.location;
let { hash } = props.location;
if (pathname === '/') { if (pathname === '/') {
hash = hash.split('?')[0];
switch (hash) { switch (hash) {
case '#send-transaction': case '#send-transaction':
case '#offline-transaction': case '#offline-transaction':
history.push('/send-transaction'); return <RedirectWithQuery from={pathname} to={'account/send'} />;
break;
case '#generate-wallet': case '#generate-wallet':
history.push('/'); history.push('/');
break; break;
@ -125,9 +127,9 @@ const LegacyRoutes = withRouter(props => {
return ( return (
<Switch> <Switch>
<Redirect from="/signmsg.html" to="/sign-and-verify-message" /> <RedirectWithQuery from="/signmsg.html" to="/sign-and-verify-message" />
<Redirect from="/helpers.html" to="/helpers" /> <RedirectWithQuery from="/helpers.html" to="/helpers" />
<Redirect from="/send-transaction" to="/account/send" /> <RedirectWithQuery from="/send-transaction" to={'/account/send'} />
</Switch> </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 { SideBar } from './components/index';
import { getWalletInst } from 'selectors/wallet'; import { getWalletInst } from 'selectors/wallet';
import { AppState } from 'reducers'; 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 { import {
WalletInfo, WalletInfo,
RequestPayment, RequestPayment,
@ -68,7 +69,7 @@ class SendTransaction extends React.Component<Props> {
exact={true} exact={true}
path={currentPath} path={currentPath}
render={() => ( render={() => (
<Redirect <RedirectWithQuery
from={`${currentPath}`} from={`${currentPath}`}
to={`${wallet.isReadOnly ? `${currentPath}/info` : `${currentPath}/send`}`} to={`${wallet.isReadOnly ? `${currentPath}/info` : `${currentPath}/send`}`}
/> />