Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with using react-router-dom version 6 #52

Open
mehmetyilmaz001 opened this issue Feb 22, 2022 · 1 comment
Open

Problem with using react-router-dom version 6 #52

mehmetyilmaz001 opened this issue Feb 22, 2022 · 1 comment

Comments

@mehmetyilmaz001
Copy link

mehmetyilmaz001 commented Feb 22, 2022

Hi,

I have just wanted to implement with react-router-dom 6.2.1 and go an error like this

Error: [Authenticator] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>

My code is

import { Callback, makeAuthenticator } from "react-oidc";
import userManager from "./oidc_config";
import { Route, BrowserRouter as Router, Routes } from "react-router-dom";
import history from "./history";
import RouteList from './RouteList';

const AppWithAuth = makeAuthenticator({
  userManager: userManager,
  signinArgs: { state: window.location.href },
})(RouteList);

function App() {
  return (
    <div className="App">
      <Router>
        <Routes>
          <Route
            path="/signin-oidc"
            element={() => (
              <Callback
                onSuccess={(_) => {
                  history.push("/");
                }}
                userManager={userManager}
              />
            )}
          />
          <AppWithAuth />
        </Routes>
      </Router>
    </div>
  );
}

export default App;

package.json

{
  "name": "react-oidc-sample",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^12.0.0",
    "@testing-library/user-event": "^13.2.1",
    "@types/jest": "^27.0.1",
    "@types/node": "^16.7.13",
    "@types/react": "^17.0.20",
    "@types/react-dom": "^17.0.9",
    "oidc-client": "^1.11.5",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-oidc": "^1.0.3",
    "react-router-dom": "^6.2.1",
    "react-scripts": "5.0.0",
    "typescript": "^4.4.2",
    "web-vitals": "^2.1.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 
```1 safari version"
    ]
  }
}


Thanks

@GrumpyGoslin
Copy link

I got this working by using the <Outlet /> is r6

const MainApp: FC = () => {
  return (
    <>
      <div>header</div>
      <Outlet />
    </>
  );
};
const Application = makeAuthenticator({
  userManager: user,
})(MainApp)

<BrowserRouter>
     <Routes>
         <Route
                path='/callback'
                element={
                  <Callback
                    onSuccess={() => ....}
                    onError={(e) => {
                      console.error(e);
                    }}
                    userManager={user}
                  />
                }
              /> 
          <Route element={<Application />}>
                <Route path="/" element={<Landing />} />
                <Route path="/path1" element={<Component1 />} />
                <Route path="/path2" element={<Component2 />} />
           </Route>
   </Routes>
</BrowserRouter>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants