o primeiro erro, é pq voce precisa definir sua estrutura de rotas. se nao voce nao vai conseguir usar o
//index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import './layout/bootstrap';
import AuthOrApp from './authOrApp';
import store from './store'
ReactDOM.render(
<Provider store={store}>
<React.StrictMode>
<AuthOrApp />
</React.StrictMode>
</Provider>,
document.getElementById('root')
);
//ponto de entrada da aplicacao
//preste atencao que se existir usuario logado eu ja envio para o routes.
import React, { useEffect } from 'react'
import { useSelector, useDispatch } from 'react-redux';
import Routes from './routes'
import Login from './pages/Login'
import { validate } from './store/auth';
const AuthOrApp = ({ children }) => {
const { user, valid } = useSelector(state => state.auth);
const dispatch = useDispatch();
useEffect(() => {
if (user) {
dispatch(validate(user.token));
}
}, [dispatch, user]);
return (
<>
{user && valid &&
<Routes>{children}</Routes>
}
{!user && !valid &&
<Login />
}
</>
)
}
export default AuthOrApp;
import React from 'react';
import { Redirect, Route, Switch } from 'react-router';
import { BrowserRouter } from 'react-router-dom'
import Login from './pages/Login';
import Header from './layout/Header';
import Footer from './layout/Footer';
import Cotacao from './pages/Cotacao';
import CotacaoResposta from './pages/CotacaoResposta'
export default function Routes() {
return (
<>
//Agora aqui dentro dessa estrutura envolvida pelo BrowserRoute os componentes serao
//renderizados e eu vou conseguir usar o Link dentro deles. veja se a sua
//aplicacao esta assim.
<BrowserRouter>
<Header />
<div className="content-wrapper">
<Switch>
<Route path='/login' component={Login} />
<Route path="/cotacao/:id_cotacao/responder" component={CotacaoResposta} />
<Route path='/' component={Cotacao} exact />
<Redirect from='*' to='/' />
</Switch>
</div>
<Footer />
</BrowserRouter>
</>
)
}
//Nesse componente tem um exemplo do link la no final.
import React, { useEffect, useState } from 'react';
import { useSelector } from 'react-redux'
import { Link } from 'react-router-dom';
import api from '../../services/api';
import ContentHeader from '../../layout/ContentHeader'
import Content from '../../layout/Content'
function Cotacao({ history }) {
const { user } = useSelector(state => state.auth.user);
const [cotacoes, setCotacoes] = useState([]);
useEffect(() => {
async function loadCotacoes() {
const response = await api.get('/cotacoes');
setCotacoes(response.data);
}
if (user.id) {
loadCotacoes();
}
}, [user.id]);
return (
<>
<ContentHeader title="Listagem de cotações" small="" />
<Content>
<div className="table-responsive">
<table className="table table-striped">
<thead>
<tr>
<th>Descrição</th>
<th>Data Inicial</th>
<th>Data Final</th>
<th>Ação</th>
</tr>
</thead>
<tbody>
{
cotacoes.map(cotacao => (
<tr key={cotacao.id}>
<td>{cotacao.descricao}</td>
<td>{cotacao.dataInicial}</td>
<td>{cotacao.dataFinal}</td>
<td>
<Link to={`/cotacao/${cotacao.id}/responder`}>Responder</Link>
</td>
</tr>
))
}
{cotacoes.lengh === 0 && <tr><td colSpan="4">Nenhuma cotação em aberto</td></tr>}
</tbody>
</table>
</div>
</Content>
</>
);
}
export default Cotacao;
MenuSystem.tsx:14 Uncaught TypeError: history.push is not a function
at SiderSystem (MenuSystem.tsx:14)
at onClick (SubPopupMenu.js:265)
at MenuItem._this.onClick (MenuItem.js:104)
at HTMLUnknownElement.callCallback (react-dom.development.js:188)
at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
at invokeGuardedCallback (react-dom.development.js:292)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:306)
at executeDispatch (react-dom.development.js:389)
at executeDispatchesInOrder (react-dom.development.js:414)
at executeDispatchesAndRelease (react-dom.development.js:3278)
at executeDispatchesAndReleaseTopLevel (react-dom.development.js:3287)
at forEachAccumulated (react-dom.development.js:3259)
at runEventsInBatch (react-dom.development.js:3304)
at runExtractedPluginEventsInBatch (react-dom.development.js:3514)
at handleTopLevel (react-dom.development.js:3558)
at batchedEventUpdates$1 (react-dom.development.js:21871)
at batchedEventUpdates (react-dom.development.js:795)
at dispatchEventForLegacyPluginEventSystem (react-dom.development.js:3568)
at attemptToDispatchEvent (react-dom.development.js:4267)
at dispatchEvent (react-dom.development.js:4189)
at unstable_runWithPriority (scheduler.development.js:653)
at runWithPriority$1 (react-dom.development.js:11039)
at discreteUpdates$1 (react-dom.development.js:21887)
at discreteUpdates (react-dom.development.js:806)
at dispatchDiscreteEvent (react-dom.development.js:4168)
SiderSystem @ MenuSystem.tsx:14
onClick @ SubPopupMenu.js:265
MenuItem._this.onClick @ MenuItem.js:104
callCallback @ react-dom.development.js:188
invokeGuardedCallbackDev @ react-dom.development.js:237
invokeGuardedCallback @ react-dom.development.js:292
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:306
executeDispatch @ react-dom.development.js:389
executeDispatchesInOrder @ react-dom.development.js:414
executeDispatchesAndRelease @ react-dom.development.js:3278
executeDispatchesAndReleaseTopLevel @ react-dom.development.js:3287
forEachAccumulated @ react-dom.development.js:3259
runEventsInBatch @ react-dom.development.js:3304
runExtractedPluginEventsInBatch @ react-dom.development.js:3514
handleTopLevel @ react-dom.development.js:3558
batchedEventUpdates$1 @ react-dom.development.js:21871
batchedEventUpdates @ react-dom.development.js:795
dispatchEventForLegacyPluginEventSystem @ react-dom.development.js:3568
attemptToDispatchEvent @ react-dom.development.js:4267
dispatchEvent @ react-dom.development.js:4189
unstable_runWithPriority @ scheduler.development.js:653
runWithPriority$1 @ react-dom.development.js:11039
discreteUpdates$1 @ react-dom.development.js:21887
discreteUpdates @ react-dom.development.js:806
dispatchDiscreteEvent @ react-dom.development.js:4168
react-dom.development.js:327 Uncaught TypeError: history.push is not a function
at SiderSystem (MenuSystem.tsx:14)
at onClick (SubPopupMenu.js:265)
at MenuItem._this.onClick (MenuItem.js:104)
at HTMLUnknownElement.callCallback (react-dom.development.js:188)
at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
at invokeGuardedCallback (react-dom.development.js:292)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:306)
at executeDispatch (react-dom.development.js:389)
at executeDispatchesInOrder (react-dom.development.js:414)
at executeDispatchesAndRelease (react-dom.development.js:3278)
at executeDispatchesAndReleaseTopLevel (react-dom.development.js:3287)
at forEachAccumulated (react-dom.development.js:3259)
at runEventsInBatch (react-dom.development.js:3304)
at runExtractedPluginEventsInBatch (react-dom.development.js:3514)
at handleTopLevel (react-dom.development.js:3558)
at batchedEventUpdates$1 (react-dom.development.js:21871)
at batchedEventUpdates (react-dom.development.js:795)
at dispatchEventForLegacyPluginEventSystem (react-dom.development.js:3568)
at attemptToDispatchEvent (react-dom.development.js:4267)
at dispatchEvent (react-dom.development.js:4189)
at unstable_runWithPriority (scheduler.development.js:653)
at runWithPriority$1 (react-dom.development.js:11039)
at discreteUpdates$1 (react-dom.development.js:21887)
at discreteUpdates (react-dom.development.js:806)
at dispatchDiscreteEvent (react-dom.development.js:4168)
o history ele vai por destruction { history }. da forma que voce esta usando nao vai funcionar. Use Link, nao use o history. O Link nao deve estar funcionando pq essa sua sidebar, deve estar carregando fora do Router. faz assim, coloca o Router no te index para ficar assim:
Failed to compile.
C:/Docker/react/MegaHack_Sebrae_Web/src/index.tsx
TypeScript error in C:/Docker/react/MegaHack_Sebrae_Web/src/index.tsx(7,18):
No overload matches this call.
Overload 1 of 2, '(props: Readonly<RouterProps>): Router', gave the following error.
Property 'history' is missing in type '{ children: Element; }' but required in type 'Readonly<RouterProps>'.
Overload 2 of 2, '(props: RouterProps, context?: any): Router', gave the following error.
Property 'history' is missing in type '{ children: Element; }' but required in type 'Readonly<RouterProps>'. TS2769
5 | import App from "./App";
6 |
> 7 | ReactDOM.render(<Router><App /></Router>, document.getElementById('root'));
| ^
8 |
9 |