An warware: React na'ura mai ba da hanya tsakanin hanyoyin sadarwa yana aiki

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.

// Wannan layin yana haifar da nau'in div wanda zai ฦ™unshi dukkan hanyoyin mu da hanyoyin haษ—in gwiwa.

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. // Wannan layin yana ฦ™irฦ™irar hanya don kusan shafin aikace-aikacen mu kuma yana sanya Game da bangaren lokacin da mai amfani ya shiga.

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.

Shafi posts:

Leave a Comment