An warware: amsa na'ura mai ba da hanya tsakanin hanyoyin sadarwa saman shafi na gaba

Babban matsalar da ke da alaฦ™a da saman shafi na React Router shine cewa yana iya haifar da halayen da ba a zata ba yayin kewayawa tsakanin shafuka. Lokacin zagawa zuwa sabon shafi, mai binciken zai koma saman shafin, wanda zai iya zama mai ban tsoro ga masu amfani waษ—anda ke tsammanin zama a kan shafi ษ—aya ko gungura ฦ™asa gaba. Bugu da ฦ™ari, wannan hali bazai iya tsammanin masu amfani waษ—anda aka yi amfani da su don ฦ™arin tsarin kewayawa yanar gizo na gargajiya ba.

import { useRouter } from 'react-router-dom';

const NextPage = () => {
  const router = useRouter();

  const handleClick = () => {
    router.push('/next-page');
  };

  return (
    <div>
      <button onClick={handleClick}>Go to next page</button>
    </div>  
  );  
};

Layin 1: Wannan layin yana shigo da ฦ™ugiya mai amfani da mai amfani daga ษ—akin karatu na react-router-dom.
// Layin 3: Wannan layin yana bayyana wani aiki mai suna NextPage wanda ke dawo da bangaren React.
// Layin 4: Wannan layin yana bayyana maษ“alli da ake kira na'ura mai ba da hanya tsakanin hanyoyin sadarwa kuma ya sanya shi zuwa ฦ™ugiya mai amfani.
Layin 6: Wannan layin yana bayyana wani aiki da ake kira handleClick wanda ke kiran hanyar turawa ta hanyar sadarwa tare da hujjar '/ shafi na gaba'.
Layi na 8-11: Waษ—annan layin suna dawo da bangaren React tare da maษ“alli mai maษ“alli wanda ke da saitin onClick don sarrafa Danna. Lokacin da aka danna, wannan zai kira aikin dannawa kuma kewaya zuwa '/shafi na gaba'.

Kewaya tsakanin shafuka

React Router babban ษ—akin karatu ne mai ba da hanya tsakanin hanyoyin sadarwa wanda aka gina a saman React wanda ke taimaka muku ฦ™ara sabbin fuska kuma yana gudana zuwa aikace-aikacenku cikin sauri, duk yayin kiyaye URL ษ—in tare da abin da ake nunawa akan shafin. React Router yana sauฦ™aฦ™a kewayawa tsakanin shafuka a cikin aikace-aikacen React ta amfani da tsarin tushen sa. Tare da taimakon abubuwan haษ—in gwiwa kamar Link, NavLink, da Redirect, zaku iya ฦ™irฦ™irar hanyoyin kewayawa masu ฦ™arfi da mu'amala waษ—anda ke ba masu amfani damar kewaya app ษ—in ku ba tare da shigar da URLs da hannu ba. Bugu da ฦ™ari, zaku iya amfani da abun tarihin da React Router ya bayar don kewaya cikin tsari tsakanin shafuka a cikin aikace-aikacenku.

GunguraToTop ko saman shafi na gaba

ScrollToTop siffa ce a cikin React Router wanda ke ba masu amfani damar gungurawa da sauri zuwa saman shafin yayin kewayawa tsakanin hanyoyi daban-daban. Yana da amfani musamman ga dogayen shafuka masu tarin abun ciki, saboda yana bawa masu amfani damar yin tsalle sama da sauri zuwa sama ba tare da gungurawa da hannu ba. Saman shafi na gaba wani nau'in fasalin ne wanda ke aiki iri ษ—aya amma maimakon gungurawa baya, yana ษ—aukar ku kai tsaye zuwa shafi na gaba lokacin kewayawa tsakanin hanyoyi. Wannan na iya zama taimako musamman ga masu amfani waษ—anda ke neman takamaiman bayani akan wani shafi kuma ba sa son yin gungurawa cikin duk abubuwan da ke wasu shafuka kafin isa wurin. Dukansu fasalulluka sune babban ฦ™ari waษ—anda ke taimakawa haษ“aka ฦ™warewar mai amfani da sauฦ™aฦ™e kewayawa da sauri.

Shafi posts:

Leave a Comment