Babban matsalar da ke da alaฦa da React Router Link ita ce rashin sabunta tarihin mai binciken yadda ya kamata idan aka danna. Wannan yana nufin cewa idan mai amfani ya danna hanyar haษi sannan ya danna maษallin baya, za a mayar da shi zuwa shafin da ya gabata maimakon shafin da ya tafi daga baya. Bugu da ฦari, wannan na iya haifar da halayen da ba zato ba tsammani a wasu lokuta, kamar lokacin amfani da igiyoyin tambaya ko guntun zanta.
import { BrowserRouter as Router, Route, Link } from "react-router-dom"; <Router> <div> <Link to="/">Home</Link> <Link to="/about">About</Link> <Route exact path="/" component={Home} /> <Route path="/about" component={About} /> </div> </Router>
1. shigo da { BrowserRouter a matsayin na'ura mai ba da hanya tsakanin hanyoyin sadarwa, Route, Link} daga "react-router-dom";
// Wannan layin yana shigo da kayan aikin BrowserRouter, Route da Link daga ษakin karatu na react-router-dom.
2.
// Wannan layin yana ฦirฦirar bangaren na'ura mai ba da hanya tsakanin hanyoyin sadarwa wanda za a yi amfani da shi don ฦirฦirar hanyoyi don aikace-aikacen mu.
3.
4. Gida
// Wannan layin yana haifar da hanyar haษi zuwa shafin gida na aikace-aikacen mu tare da rubutun 'Gida'.
5. Game da
// Wannan layin yana haifar da hanyar haษi zuwa shafin game da aikace-aikacen mu tare da rubutun 'Game da'.
6.
// Wannan layin yana ฦirฦirar hanya don shafin farko na aikace-aikacen mu kuma yana samar da bangaren Gida lokacin da mai amfani ya shiga.
7.
8.
// Wannan yana rufe abubuwan div ษin mu wanda ya ฦunshi duk hanyoyinmu da hanyoyin haษin yanar gizon mu
Hanyar haษi v6
Link v6 sabon abu ne a cikin React Router wanda ke ba da sanarwa, mafita mai sauฦi don aikace-aikacen React. Yana maye gurbin sashin haษin gwiwar da ya gabata kuma yana ba da ฦarin fasali da ingantaccen tallafi don samun dama. Link v6 yana goyan bayan hanyoyin haษin yanar gizo na yau da kullun da kuma ษorewa mai ฦarfi, yana ba masu haษaka damar ฦirฦirar ฦwarewar kewayawa mai ฦarfi ba tare da sarrafa hanyoyi da hannu ba ko amfani da ษakunan karatu na ษangare na uku. Hakanan yana goyan bayan ma'anar sabar-gefen sabar, wanda ke ba masu haษaka damar ฦirฦirar aikace-aikacen abokantaka na SEO tare da ฦaramin ฦoฦari. A ฦarshe, Link v6 yana da ginanniyar goyan baya don bin diddigin nazari, yana sauฦaฦa bin mu'amalar mai amfani tare da aikace-aikacen ku.
Me yasa React Router Link baya aiki
Akwai dalilai da yawa masu yiwuwa dalilin da yasa React Router Link baya aiki a cikin React Router. Babban dalilin da ya fi dacewa shi ne, ษangaren da ake haษa shi da shi ba a tsara shi yadda ya kamata ko kuma an saita shi ba. Misali, idan ba a shigo da bangaren da ake dangantawa da shi daidai ba, ko kuma idan hanyar ba daidai ba ce, to React Router Link ba zai yi aiki ba. Bugu da ฦari, idan akwai wasu typos a cikin hanyar hanya ko sunan bangaren, wannan kuma na iya haifar da matsala tare da React Router Link. A ฦarshe, idan akwai rikice-rikice tsakanin hanyoyi masu yawa (kamar hanyoyi guda biyu tare da ainihin hanya ษaya), wannan kuma yana iya haifar da matsala tare da React Router Link.