Babban matsalar da ke da alaฦa da zazzagewar React Router DOM shine cewa yana iya zama da wahala a daidaitawa da saitawa. React na'ura mai ba da hanya tsakanin hanyoyin sadarwa DOM yana buฦatar tsari mai yawa da saiti, wanda zai iya ษaukar lokaci da rikitarwa ga masu haษakawa waษanda suke sababbi zuwa ษakin karatu. Bugu da ฦari, React Router DOM yana ci gaba koyaushe, don haka dole ne masu haษakawa su ci gaba da sabuntawa tare da sabon sigar don tabbatar da dacewa da aikace-aikacen su.
import { BrowserRouter as Router, Route } from "react-router-dom"; ReactDOM.render( <Router> <Route path="/"> <App /> </Route> </Router>, document.getElementById('root'));
1. "shigo da { BrowserRouter azaman na'ura mai ba da hanya tsakanin hanyoyin sadarwa, Hanyar } daga 'react-router-dom';" - Wannan layin yana shigo da kayan aikin BrowserRouter da Route daga ษakin karatu na react-router-dom.
2. "ReactDOM.render("- Wannan layin yana kiran hanyar bayar da ReactDOM don samar da wani abu na React a cikin DOM a cikin kwandon da aka kawo da kuma mayar da tunani ga bangaren (ko ya dawo da banza don abubuwan da ba su da ฦasa).
3. "
4. "
5. "
Bangaren App na iya zama kowane ษangaren React ษin da muka ayyana a wani wuri a cikin codebase ko shigo da shi daga wani ษakin karatu ko fakiti kamar Material UI ko Bootstrap da sauransuโฆ
6. "" - Wannan alama ce ta rufe Rute Component wanda aka buษe akan layi na 4 a sama, yana rufe wannan ฦayyadaddun ma'anar hanya ta yadda za a iya ฦara wasu hanyoyin idan an buฦata daga baya a cikin codebase ษinmu ba tare da rinjayar wannan aikin ko halinsa ba. .
7. โโ โ Wannan alama ce ta rufe Rukunin Rukunin da aka buษe akan layi na 3 a sama, yana rufe wannan takamaiman maโanar naโura mai ba da hanya tsakanin hanyoyin sadarwa ta yadda za a iya ฦara sauran hanyoyin sadarwa idan an buฦata daga baya a cikin codebase ษinmu ba tare da shafar aikin wannan mutum ko halayensa ba. ..
8.document.getElementById('tushen'));" - A ฦarshe, mun wuce a cikin takaddun getElementById ('tushen') azaman hujja don hanyar ReactDOM wanda ke gaya masa inda daidai muke son hawa / fitar da app a cikin itacen DOM (a cikin wannan yanayin a cikin wani abu tare da id = " tushen").
react-router-dom kunshin
React Router sanannen ษakin karatu ne na kewayawa don React. Yana ba da API mai ฦarfi, mai sauฦin amfani don sarrafa hanyoyin aikace-aikace da kewayawa. Kunshin react-router-dom shine sigar hukuma ta React Router don aikace-aikacen yanar gizo. Yana bayar da abubuwa kamar da kuma
Yadda ake zazzage na'ura mai ba da hanya tsakanin hanyoyin sadarwa dom Code Misali
1. Sanya React Router Dom:
A cikin kundin tsarin aikin ku, gudanar da umarni mai zuwa don shigar da React Router Dom:
'npm shigar react-router-dom'
2. Shigo React Router Dom:
Da zarar kun shigar da React Router Dom, zaku iya shigo da shi cikin aikin ku tare da lambar mai zuwa:
'shigo da { BrowserRouter azaman Router, Route} daga 'react-router-dom''
3. ฦirฦiri Bangaren Hanya:
Na gaba, ฦirฦiri ษangaren hanya wanda zai ba da shafin lokacin da mai amfani ya ziyarci ฦayyadadden hanyar. Misali, idan kuna son yin shafi lokacin da wani ya ziyarci / gida a cikin aikace-aikacen ku, zaku iya amfani da lambar mai zuwa:
`
4. Kunna App ษinku tare da Na'ura mai ba da hanya tsakanin hanyoyin sadarwa:
A ฦarshe, kunsa app ษinku tare da bangaren na'ura mai ba da hanya tsakanin hanyoyin sadarwa domin duk hanyoyinku za su kasance daidai. Kuna iya yin haka ta amfani da lambar da ke gaba a cikin tushen fayil ษinku (yawanci index.js): `