Babban matsalar da ke da alaฦa da React Router yarn shine cewa yana iya zama da wahala a daidaita shi daidai. Yana buฦatar saiti da tsari da yawa, kuma idan aka yi ba daidai ba, zai iya haifar da hali ko kurakurai da ba a zata ba. Bugu da ฦari, takaddun don yarn na React Router ba koyaushe bane bayyananne ko na zamani, yana sa ya zama da wahala ga masu haษakawa don magance matsalolin.
add react-router-dom import { BrowserRouter as Router, Route, Link } from "react-router-dom"; <Router> <div> <ul> <li><Link to="/">Home</Link></li> <li><Link to="/about">About</Link></li> <li><Link to="/topics">Topics</Link></li> </ul> <hr /> <Route exact path="/" component={Home} /> <Route path="/about" component={About} /> <Route path="/topics" component={Topics} /> </div> </Router>
1. Wannan layin yana shigo da kayan aikin BrowserRouter, Route, da Link daga ษakin karatu na react-router-dom:
shigo da { BrowserRouter azaman na'ura mai ba da hanya tsakanin hanyoyin sadarwa, Hanya, Link} daga "react-router-dom";
2. Wannan layin yana nannade aikace-aikacen gabaษaya a cikin ษangaren na'ura mai ba da hanya tsakanin hanyoyin sadarwa don samar da ayyukan sarrafa hanya:
3. Wannan nau'in div ya ฦunshi jerin hanyoyin haษin da za a yi amfani da su don kewaya tsakanin hanyoyi daban-daban:
- Gida
- Game da
- Topics
4. Ana amfani da wannan kashi na hr azaman mai raba gani tsakanin hanyoyin kewayawa da abun cikin hanya:
5. Waษannan layukan sun bayyana hanyoyi daban-daban guda uku don aikace-aikacenmu ta amfani da bangaren Hanyar Hanyar React Router:
6. A ฦarshe, wannan rufewar div tag yana rufe kayan aikin mu na abin rufe fuska:
Menene React Router
React Router babban ษakin karatu ne don React wanda ke ba masu haษakawa damar ฦirฦira da sarrafa hanyoyin cikin aikace-aikacen React ษin su. Yana ba da hanya don bayyana taswirar hanyoyin zuwa abubuwan haษin gwiwa, sarrafa sigogin URL, da sarrafa abubuwan kewayawa. Hakanan yana ba da fasali kamar daidaitawar hanya mai ฦarfi, sarrafa canjin wuri, da maidowa gungurawa.
Menene Yarn
Yarn shine mai sarrafa fakitin don JavaScript wanda ke taimaka wa masu haษakawa sarrafa abubuwan dogaronsu ta hanya mafi inganci da aminci. React Router ke amfani dashi don shigarwa, sabuntawa, da daidaita fakiti. Yarn kuma yana taimaka wa masu haษakawa su lura da abin da suka dogara da aikin su, tabbatar da cewa an shigar da duk fakitin da suka dace da kuma na zamani. Wannan yana sauฦaฦa yin aiki akan ayyuka tare da masu haษakawa da yawa kamar yadda kowane ษayan zai iya bincika nau'ikan fakitin da suke buฦatar amfani da su cikin sauฦi.