Amplify-js: Add withRouter HOC for React, or add Router as option for withAuthenticator HOC

Created on 14 Dec 2018  路  1Comment  路  Source: aws-amplify/amplify-js

Is your feature request related to a problem? Please describe.
I'm trying to convert my Amplify React site to use react-router to route requests to individual pages with, in this case, their own Sumerian scenes.

Describe the solution you'd like
Have option to tell withAuthenticator to wrap the passed component in <BrowserRouter></BrowserRouter>.

Describe alternatives you've considered
Wrote this file, seems to work:

HigherOrderComponents.jsx

import React, {Component} from 'react';
import { BrowserRouter, Link } from 'react-router-dom';

function withRouter(Comp) {
    return class extends Component {
        constructor(props) {
            super(props);
            this.state = {};
        }

        render() {
          return (
            <BrowserRouter>
              <Comp />
            </BrowserRouter>
          ); 
        }
    };
}

export { withRouter };

index.jsx

import App from './App';
const appWithAuthAndRouter = withAuthenticator(withRouter(App));

Most helpful comment

I sure know how to find the hard way to solve a problem.

https://reacttraining.com/react-router/web/api/withRouter

>All comments

I sure know how to find the hard way to solve a problem.

https://reacttraining.com/react-router/web/api/withRouter

Was this page helpful?
0 / 5 - 0 ratings