An warware: amsa hanyar haɗin yanar gizo na waje

Babban matsalar da ke da alaƙa da hanyoyin haɗin waje na React Router shine cewa suna iya haifar da halayen da ba zato ba tsammani yayin kewayawa tsakanin shafuka daban-daban. Misali, idan mai amfani ya danna hanyar haɗin waje yayin da yake kan shafin React Router, mai binciken zai yi nisa daga shafin na yanzu maimakon yawo zuwa sabon shafin da ke cikin aikace-aikacen. Wannan na iya haifar da rudani da takaici ga masu amfani waɗanda ke tsammanin sauyi mai sauƙi tsakanin shafuka. Bugu da ƙari, hanyoyin haɗin waje na iya haifar da al'amura tare da SEO tun da injunan bincike na iya ba za su iya tsara abun ciki da kyau daga tushen waje ba.

import { Link } from "react-router-dom";

<Link to="https://www.example.com" target="_blank" rel="noopener noreferrer">External Link</Link>

1. Wannan layin yana shigo da bangaren Link daga react-router-dom library.
2. Wannan layin yana haifar da hanyar haɗin yanar gizon da za ta tura zuwa "https://www.example.com" idan aka danna, sannan a buɗe shi a cikin sabon shafin ba tare da bayanin mai aikawa zuwa sabon shafin ba. Rubutun hanyar haɗin zai zama "Haɗin waje".

Menene hanyar haɗin waje

Hanya na waje a cikin React Router hanya ce ta hanyar da ke ɗaukar mai amfani zuwa shafi na wajen aikace-aikacen. Wannan na iya zama gidan yanar gizo na waje, ko wani aikace-aikace. Ana amfani da hanyoyin haɗin waje don samarwa masu amfani ƙarin bayani ko albarkatun da suka shafi abun ciki a cikin aikace-aikacen. Hakanan ana iya amfani da su azaman hanyar kai masu amfani zuwa wasu aikace-aikace ko gidajen yanar gizo don ƙarin bincike.

Yadda ake ƙara hanyar haɗin waje tare da React Router

Ƙara hanyar haɗin waje tare da React Router a cikin React Router tsari ne mai sauƙi. Da farko, kuna buƙatar shigo da bangaren haɗin gwiwa daga fakitin react-router-dom. Sannan, zaku iya amfani da bangaren mahaɗin don ƙirƙirar hanyar haɗi zuwa URL na waje. Jumla don ƙirƙirar hanyar haɗin gwiwa yayi kama da haka:

Misali, idan kuna son ƙirƙirar hanyar haɗi zuwa Google, zai yi kama da wannan:

Google

Da zarar kun ƙirƙiri hanyar haɗin yanar gizon ku, zaku iya ƙara ƙarin abubuwan samarwa kamar manufa da sifofi don ingantacciyar damar isa ga dalilai na tsaro. Misali:

Google

Shafi posts:

Leave a Comment