aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

Add withRouter HOC for React, or add Router as option for withAuthenticator HOC #2349

Closed jkeys-ecg-nmsu closed 5 years ago

jkeys-ecg-nmsu commented 5 years ago

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));
jkeys-ecg-nmsu commented 5 years ago

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

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

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.