A cikin yanayin ci gaban yanar gizo na zamani, kewayawa mara kyau da tasiri routing suna da mahimmanci don ƙirƙirar ƙwarewar mai amfani. Nuxt.js, ƙaƙƙarfan tsarin Vue.js, yana sauƙaƙe da haɓaka tsarin aiki routing da kewayawa, yana sa ya zama mara wahala don ƙirƙirar gidan yanar gizo mai ƙarfi route.
A cikin wannan labarin, za mu zurfafa cikin ɓarna na routing da kewayawa a cikin Nuxt.js, muna tattaunawa kan yadda Nuxt.js ke sarrafa route ƙira da ba da jagora kan ƙera al'ada route da aiwatar da kewayawa.
Fahimtar Ƙarfafa Ta Nuxt.js atomatik Route
Ofaya daga cikin abubuwan ban mamaki Nuxt.js shine ƙirƙirar ta atomatik route. Ba kamar saitin al'ada ba inda route ake buƙatar daidaitawa da hannu, Nuxt.js ƙirƙira da basira route bisa tsarin fayil ɗin cikin pages
kundin adireshi. Kowane .vue
fayil a cikin wannan kundin adireshi ya zama route, kuma ƙananan kundin adireshi suna ƙirƙirar gida route.
Wannan tsarin yana daidaita tsarin tsarin ƙirƙira route, musamman don manyan ayyuka, rage yuwuwar kurakurai da adana lokacin haɓakawa.
Ƙirƙirar Al'ada Route
Yayin da route tsara ta atomatik ya dace, Nuxt.js kuma yana ba ku damar ƙera al'ada route wanda ya dace da bukatun aikin ku. Don ƙirƙirar al'ada route, bi waɗannan matakan:
- A cikin
pages
directory, ƙirƙiri.vue
fayil mai suna wanda ya dace da abin da kuke so route, misali,my-custom-route.vue
. - Ƙayyade tsari da abun ciki na al'ada route ta amfani da abubuwan Vue.js da abubuwan HTML.
- Da zarar
.vue
an ƙirƙiri fayil ɗin, Nuxt.js za ta gane shi ta atomatik azaman route mai iya samun dama ta URL ɗin sa.
Wannan sassauci yana ba masu haɓaka damar ƙira route waɗanda suka dace daidai da ƙira da aikin aikace-aikacen.
Ana aiwatar da Kewayawa
A cikin Nuxt.js, kewayawa tsakanin route ana samun ta hanyar <nuxt-link>
bangaren. Wannan bangaren yana sauƙaƙe kewayawa ta hanyar warware hanyoyi ta atomatik bisa route sunan sunan. Misali, <nuxt-link to="/about">About</nuxt-link>
zai haifar da hanyar haɗi zuwa /about
route. Bugu da ƙari, Nuxt.js yana ba da kewayawa na shirye-shirye ta hanyar $router
abu, yana ba da damar kewayawa mai ƙarfi dangane da hulɗar mai amfani ko canje-canjen bayanai.
Kammalawa
Routing da kewayawa su ne muhimman abubuwan ci gaban yanar gizo, suna tasiri haɗin gwiwar mai amfani da amfani da aikace-aikacen gabaɗaya. Nuxt.js daidaita tsari ta hanyar sarrafa route ƙira da bayar da sassauci ga al'ada route. Abubuwan ginanniyar kewayawa da kayan aikin kewayawa na shirye-shirye suna ƙara haɓaka ƙwarewar mai amfani.
Ta ƙware routing da kewayawa a cikin Nuxt.js, zaku iya ƙirƙirar aikace-aikacen gidan yanar gizo masu dacewa da mai amfani waɗanda ke jan hankali da gamsar da masu sauraron ku.