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

Babban matsalar da ke da alaฦ™a da sunan ClassActive a cikin React Router shine cewa baya sabunta aji mai aiki kai tsaye lokacin da hanya ta canza. Wannan yana nufin cewa masu haษ“akawa dole ne su sabunta aji mai aiki da hannu a duk lokacin da hanya ta canza, wanda zai iya ษ—aukar lokaci da kuskure. Bugu da ฦ™ari, idan an haษ—a hanyoyi da yawa a tsakanin juna, zai iya zama da wahala a lura da wace hanya ce ke aiki a halin yanzu da kuma waษ—anne azuzuwan ya kamata a yi amfani da su ga kowane kashi.

<Router>
  <Link to="/about" activeClassName="active">About</Link>
</Router>

1. The Ana amfani da bangaren don ฦ™irฦ™irar na'ura mai ba da hanya tsakanin hanyoyin sadarwa a cikin React wanda ke ba masu amfani damar kewayawa tsakanin shafuka daban-daban.

2. The Ana amfani da bangaren don ฦ™irฦ™irar hanyar haษ—i wanda idan aka danna, zai kai mai amfani zuwa shafin da aka ฦ™ayyade a cikin sifa "to" (a cikin wannan yanayin, "/ game da").

3. Halin Sunan mai aiki yana ฦ™ayyadad da nau'in nau'in da ya kamata a yi amfani da shi lokacin da hanyar haษ—in ke aiki (a cikin wannan yanayin, "active").

Menene NavLink

NavLink wani bangaren React ne da ake amfani da shi a cikin React Router don ฦ™irฦ™irar hanyar kewayawa tsakanin hanyoyi daban-daban a cikin aikace-aikacen. Yana kama da sashin haษ—in kai, amma yana ฦ™ara sifofi masu salo zuwa ษ“angaren da aka yi lokacin da ya dace da URL na yanzu. NavLink kuma yana ba da tallan ClassName mai aiki wanda za'a iya amfani dashi don amfani da sunan aji lokacin da hanyar haษ—in ke aiki.

Sifa mai aikiClassName

Ana amfani da sifa mai aikiClassName a cikin React Router don tantance sunan aji wanda za'a yi amfani da shi akan kashi idan ya dace da URL na yanzu. Wannan yana da amfani don salon hanyoyin haษ—in kai ko abubuwan kewayawa lokacin da suka dace da hanyar yanzu. Hakanan ana iya amfani da shi don ฦ™ara ฦ™arin salo zuwa abubuwan da ba su da alaฦ™a kai tsaye da kewayawa, kamar nuna alamar shafin da ke aiki a halin yanzu a mashigin kewayawa.

Me yasa Sunan Class ba zai yi aiki ba

ActiveClassName siffa ce ta React Router wanda ke ba ka damar ฦ™ara aji zuwa mahaษ—in da ke aiki a cikin menu na kewayawa. Abin takaici, ba zai yi aiki a cikin React Router ba saboda ya dogara da tarihin mai binciken API, wanda babu shi a cikin React Router. Wannan yana nufin cewa React Router ba zai iya gano lokacin da mai amfani ya danna hanyar haษ—i kuma ya yi amfani da Sunan Class mai aiki daidai da haka.

Shafi posts:

Leave a Comment