//Nessecomponentetemumexemplodolinklanofinal.importReact,{useEffect,useState}from'react';import{useSelector}from'react-redux'import{Link}from'react-router-dom';importapifrom'../../services/api';importContentHeaderfrom'../../layout/ContentHeader'importContentfrom'../../layout/Content'functionCotacao({history}){const{user}=useSelector(state=>state.auth.user);const[cotacoes,setCotacoes]=useState([]);useEffect(()=>{asyncfunctionloadCotacoes(){constresponse=awaitapi.get('/cotacoes');setCotacoes(response.data);}if(user.id){loadCotacoes();}},[user.id]);return(<><ContentHeadertitle="Listagem de cotações"small=""/><Content><divclassName="table-responsive"><tableclassName="table table-striped"><thead><tr><th>Descrição</th><th>DataInicial</th><th>DataFinal</th><th>Ação</th></tr></thead><tbody>{cotacoes.map(cotacao=>(<trkey={cotacao.id}><td>{cotacao.descricao}</td><td>{cotacao.dataInicial}</td><td>{cotacao.dataFinal}</td><td><Linkto={`/cotacao/${cotacao.id}/responder`}>Responder</Link></td></tr>))}{cotacoes.lengh===0&&<tr><tdcolSpan="4">Nenhumacotaçãoemaberto</td></tr>}</tbody></table></div></Content></>);}exportdefaultCotacao;
T
thimor
O menu na minha estrutura de template, que uso o adminlte eu faco assim, sao tres componentes, MenuTree, Menu e MenuItem (aqui vai o )
importReactfrom'react'exportdefaultfunctionmenuTree(props){return(<liclassName="nav-item has-treeview"><ahref={props.path}className="nav-link"><iclassName={`nav-iconfafa-${props.icon}`}></i><p>{props.label}<iclassName="right fas fa-angle-left"></i></p></a><ulclassName="nav nav-treeview">{props.children}</ul></li>)}importReactfrom'react'import{Link}from'react-router-dom'exportdefaultfunctionmenuItem(props){return(<liclassName="nav-item"style={{marginLeft:props.marginLeft||0}}><Linkto={props.path}className="nav-link"><iclassName={`nav-iconfafa-${props.icon}`}></i><p>{props.label}</p></Link></li>)}importReactfrom'react'importMenuItemfrom'./menuItem.js'importMenuTreefrom'./menuTree'exportdefaultfunctionmenu(){return(<navclassName="mt-2"><ulclassName="nav nav-pills nav-sidebar flex-column"data-widget="treeview"role="menu"data-accordion="false"><MenuItempath="/"label='Dashboard'icon="tachometer-alt"/><MenuTreelabel="Cadastros"icon="database"><MenuItempath="/produto"label="Produto"icon="luggage-cart"marginLeft={20}/><MenuItempath="/cliente"label="Cliente"icon="address-book"marginLeft={20}/></MenuTree><MenuTreelabel="Produtos"icon="barcode"><MenuItempath="/produtos/validacaoPreco"label="Validação de preco"icon="hand-holding-usd"marginLeft={20}/><MenuItempath="/produtos/alteraPreco"label="Altera preço"icon="tag"marginLeft={20}/></MenuTree><MenuTreelabel="Caixas"icon="cash-register"><MenuItempath="/caixas/flashVendas"label="Flash de vendas"icon="dollar-sign"marginLeft={20}/></MenuTree><MenuTreelabel="Compras"icon="shopping-cart"><MenuItempath="/compras/leilao"label="Leilão"icon="gavel"marginLeft={20}/><MenuItempath="/compras/pedidoCompra"label="Pedido de compra"icon="truck-loading"marginLeft={20}/><MenuItempath="/compras/trocaMercadoriaFornecedor"label="Troca com fornecedor"icon="exchange-alt"marginLeft={20}/></MenuTree><MenuTreelabel="Comunicação"icon="satellite-dish"><MenuItempath="/comunicacao/cargaPdv"label="Carga para pdvs"icon="desktop"marginLeft={20}/><MenuItempath="/comunicacao/cargaBalanca"label="Carga para balanca"icon="balance-scale"marginLeft={20}/></MenuTree><MenuTreelabel="Utilitários"icon="tools"><MenuItempath="/utilitarios/nfceMonitoramento"label="Monitoramento NFC-e"icon="file-invoice"marginLeft={20}/></MenuTree></ul></nav>)}
G
guilhermebhte
Então, pediram no projeto para utilizar a biblioteca : https://ant.design
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: