An warware: amsa yarn na'ura mai ba da hanya tsakanin hanyoyin sadarwa

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.

Shafi posts:

Leave a Comment