An Warware: Zazzage React dom

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. ""- Wannan alama ce ta buษ—ewa don ษ“angaren na'ura mai ba da hanya tsakanin hanyoyin sadarwa wanda za a yi amfani da shi don nannade duk hanyoyin mu don samar da ayyukan sarrafa kayan aikin mu.

4. "โ€- Wannan alama ce ta buษ—ewa don ษ“angaren hanyoyin hanya wanda za a yi amfani da shi don ayyana hanya ษ—aya a cikin aikace-aikacen mu wanda zai dace da duk wani buฦ™atun da aka yi a '/'.

5. ""- Wannan alama ce ta rufe kai wanda ke haifar da ษ“angaren App a cikin bishiyar DOM ษ—in mu lokacin da wannan hanyar ta dace da dom na mai ba da hanya tsakanin hanyoyin sadarwa.
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 don taimakawa gudanar da zirga-zirga a cikin app ษ—in ku. Hakanan ya haษ—a da ฦ™ugiya kamar tarihin amfani, amfani da Location, da kuma amfani da Params don samun damar bayanan hanyar yanzu daga cikin abubuwan haษ—in ku. Tare da react-router-dom zaka iya ฦ™irฦ™irar hanyoyi masu ฦ™arfi cikin sauฦ™i dangane da sigogin URL, igiyoyin tambaya, ko ma dabaru na al'ada. Hakanan zaka iya ฦ™irฦ™irar hanyoyin gida tare da sassa masu ฦ™arfi don samar da ฦ™arin iko akan tsarin kewayawa na aikace-aikacenku.

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): ` `.

Shafi posts:

Leave a Comment