Kev siv BrowserRouter yog dab tsi?
Kev siv BrowserRouter yog dab tsi?

Video: Kev siv BrowserRouter yog dab tsi?

Video: Kev siv BrowserRouter yog dab tsi?
Video: looj phaj kev siv 2024, Kaum ib hlis
Anonim

BrowserRouter yog siv rau kev ua cov neeg siv khoom routing nrog ntu URL. Koj tuaj yeem thauj khoom qib siab tshaj plaws rau txhua txoj kev. Qhov no pab cais cov kev txhawj xeeb hauv koj lub app thiab ua rau cov logic / cov ntaub ntawv ntws kom meej.

Ib yam li ntawd, nws tau nug, BrowserRouter yog dab tsi hauv qhov tshwm sim?

Teb Router Cheebtsam Thawj ib, < BrowserRouter >, feem ntau yog muab ib lub npe ntawm 'Router' thiab qhov no yog cov khoom siv niam txiv uas siv los khaws tag nrho koj cov khoom. Cov Cheebtsam yog dab tsi qhia koj lub app uas lwm cov khoom siv los tso saib raws li txoj hauv kev.

Tsis tas li ntawd, kuv yuav siv NavLink ua li cas? Teb Router muab cov khoom siv los tsim cov kev sib txuas hauv koj daim ntawv thov . Txhua qhov chaw uas koj muab ib tug, ib tug thauj tog rau nkoj () yuav rendered nyob rau hauv koj daim ntawv thov HTML. Qhov < NavLink > yog hom tshwj xeeb uas tuaj yeem ua rau nws tus kheej ua "active" thaum nws mus rau qhov sib tw rau qhov chaw tam sim no.

Yog li ntawd, qhov tseeb prop ntawm txoj kev tiv thaiv ua li cas?

Cov prop yog siv rau txhais yog muaj yog ib qho raws nraim qhov thov txoj kev . Feem ntau nws yog siv los qhwv txoj kev tsis muaj menyuam - txoj kev (e.g. homepage).

Dab tsi yog keeb kwm hauv react router?

Lub sij hawm " keeb kwm "thiab" keeb kwm object"nyob rau hauv cov ntaub ntawv no yog hais txog cov keeb kwm pob, uas yog ib qho ntawm 2 loj dependencies ntawm React Router (dua li Teb nws tus kheej), thiab uas muab ntau qhov sib txawv rau kev tswj xyuas kev sib tham keeb kwm hauv JavaScript hauv ntau qhov chaw.

Pom zoo: