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
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.