본문 바로가기

Grew from/Trouble Shooting

Property 'history' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<BrowserRouter> & Readonly<BrowserRouterProps> & Readonly<...>'.

BrowserRouter에는 history를 세팅할 수 없다.

history 모듈로 BrowserHistory를 생성해서 넣으려면 Router 컴포넌트를 사용해야 한다.

import { Router, Route, Switch } from "react-router-dom";

export const history = createBrowserHistory();

function Routes({}: RoutesProps) {
  return (
    <Router history={history}>
      <Switch>
        <Route path="/signin" component={SigninPage} />
        <Route path="/signup" component={SignupPage} />
        <PrivateRoute exact path="/" component={HomePage} />
        <PrivateRoute path="/project" component={ProjectPage} />
        <Route render={props => <Err404 />} />
      </Switch>
    </Router>
  );
}