This problem might be a bug according to another post here React-Router v4: Cannot read property 'route' of undefined and apparently the person solved their problem by wrapping their routers in a browserRouter. However, I have done that already and still seem to be getting the error. Just like the other post, when I export my component with withRouter, it returns an error, however when I export it without it, it works fine. What I am trying to do is, find the pathname when a person loads a Route, check to see if they are authenitcated, if not, redirect to login, if they are, redirect to home. I've had this problem for a while now, if you know a solution please help me.
Routes.js
import { Meteor } from "meteor/meteor"
import React from "react";
import { withRouter, Switch, BrowserRouter, Route, Redirect, Link } from "react-router-dom";
import { Tracker } from "meteor/tracker";
import Login from "../ui/authentication/Login";
import Signup from "../ui/authentication/Signup";
import Home from "../ui/Home";
import searchNotes from "../ui/searchNotes"
import Note from "../ui/Note";
import fullSize from "../ui/fullSize"
import userProfile from "../ui/userProfile";
import AddNote from "../ui/AddNote";
import questions from "../ui/questions"
import NotFound from "../ui/NotFound";
export default class Routes extends React.Component{
render(){
const signedIn = Meteor.userId();
const UnauthPage = ["/login", "/signup"];
console.log(this.props)
// if(signedIn && ){
// console.log("Signed in")
// }
return (
<BrowserRouter>
<Switch>
<Login path="/login" />
<Signup path="/signup" />
<Route path="/" component={Home} exact/>
<Route path={`/searchNotes/:subject`} component={Note} />
<Route path={`/searchNotes`} component={searchNotes} />
<Route path={`/fullSize/:noteId`} component={fullSize}/>
<AddNote path="/addNote"/>
<Route path="/questions" component={questions} />
<Route component={userProfile} path={`/users/:userId`} />
<NotFound />
</Switch>
</BrowserRouter>
)
}
}