All language subtitles for 019 Implementing Programmatic (Imperative) Navigation_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

[Maximilian Schwarzmuller] Now this demo application

is taking shape.

Let's now take look at this, Add a Quote form.

Now we will later at the actual logic for adding a quote

for the moment, If we open the dev tools,

if I

enter some data here,

we just see it locked to the console because

that's all we're doing upon a form submission.

But let's imagine

that this actually would be sent to a server.

What would we typically expect from an application

from a website if we submitted a form.

We typically expect either some success message,

maybe a modal overlay, which opens up,

or we expect that we navigate somewhere else.

If I add a new quote

and that request was sent to the server,

I might expect

that I'm automatically navigated away from this page,

maybe to the All Quotes page.

And that is something which

I do wanna implement here as well.

Now for that of course,

we could convert our submit button here

in the QuoteForm to a link so

that it links to the All Quote page.

But actually here we don't want the link,

we want a button which submits the form.

So using a link is not an option here.

Instead, what we need here

is something called programmatic navigation.

We wanna trigger a navigation action

and navigate the user away programmatically

in our code.

So it's not a link which the user clicks to navigate away,

but it's some action triggered by our code,

when some abreaction sending the

entered data to a server finished.

And in the end we probably wanna trigger

this navigation action from inside,

the NewQuote page component here.

Because here we do have this addQuoteHandler

where we will later send the requests to the server,

and therefore it's here where we also want to navigate away.

But how can we now navigate programmatically?

How can we tell React Router that we wanna switch pages?

Well for this React Router again has a hook,

which we can import.

So we can import from react-router-dom,

and we can import the useHistory hook.

The name might be a bit strange,

but it's named like this because it allows us

to change the browser history.

So the history of pages we visited.

We call useHistory like this,

and that gives us a history object,

which we can store in a constant.

And extend this history object,

which we can use

to

trigger certain history changing actions.

And what changes the history of pages,

well, for example if we add a new page,

if we go to a new page.

And we can navigate around

with the push method here,

which pushes a new page on the stack of pages,

so a new page on our history of pages,

or we can navigate with the replace method

that replaces the current page.

The difference is that with push,

we can go back with the back button

to the page we're coming from,

with replace we can't.

So replace is like a redirect

where we changed occurred page, push adds a new page.

And it's up to you what you want.

Do you want to allow your user to go back or not

Here I'll go for push

and I will allow the user to go back,

and then here we could go to /quotes like this.

So now we will navigate away

if we send our data here

at the moment, of course,

we're only logging it to the console.

But with that if we now save this,

if I enter some

data here,

this is a test,

and I click Add Quote,

you see it's locked to the console,

but we're also navigated away.

And that is how we can implement programmatic navigation

with React Router.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.