Routing, Linking and Redirecting in Next.js

  Рет қаралды 17,836

Leigh Halliday

Leigh Halliday

Күн бұрын

Пікірлер: 59
@richierob62
@richierob62 4 жыл бұрын
👍🏾 as usual. One little thing: what is returned from useEffect is a cleanup function that’s run when the component unmounts, not actually something to render.
@leighhalliday
@leighhalliday 4 жыл бұрын
Thanks, Richard! I actually didn't use a cleanup function in this example... the `return null` was from the Redirect component itself.
@sheldonfourie5959
@sheldonfourie5959 4 жыл бұрын
if you had a course I would buy it for sure. Get on scrimba! You really are great at teaching an emphasize things in such a good way that is not boring
@leighhalliday
@leighhalliday 4 жыл бұрын
Thanks Sheldon! New course coming next week hopefully :)
@samdimahmood9047
@samdimahmood9047 4 жыл бұрын
This was a great video! Hoping to see a video on dynamic routing soon!
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Samira! I'll make sure to cover it at some point in the future :)
@jpbm6369
@jpbm6369 3 жыл бұрын
That redirect component safe lives, thank you.
@leighhalliday
@leighhalliday 3 жыл бұрын
Haha nice, glad it helped!!
@silenux7419
@silenux7419 4 жыл бұрын
Excellent video Leigh. Loving Nextjs, it surpassed Gatsby and it's my default react framework.
@leighhalliday
@leighhalliday 4 жыл бұрын
Thank you Silenux! Me too :) Loving Next.js.
@rvmyangalstar2024
@rvmyangalstar2024 2 жыл бұрын
Excellent explanation 👌👌👌👌
@leighhalliday
@leighhalliday 2 жыл бұрын
Thank you Jagan!!
@NorbyWinner
@NorbyWinner 4 жыл бұрын
👍 excellent explanation, as usual
@leighhalliday
@leighhalliday 4 жыл бұрын
Thank you very much, Norb!
@kunglane
@kunglane 4 жыл бұрын
Best Next.js explanations on YT 😀👍 THANKS
@leighhalliday
@leighhalliday 4 жыл бұрын
Thanks S OG!! I appreciate it.
@hanfriednguegan8321
@hanfriednguegan8321 3 жыл бұрын
Hey Leigh what can i do when i want to pass a state from one component to another when i use history.push() ?
@ricardovannoort
@ricardovannoort 2 жыл бұрын
Hi Leigh, great video. I was wondering what is the benefit of using the Redirect component (with additional useState and useEffect hook) over a simple router.push in a Link component or button?
@syz3981
@syz3981 3 жыл бұрын
Hey Leigh, a major problem im noticing is that the if statement causes the html content to not show inside the view source of the page . For example the if shouldRedirect is true and i get redirected to the /about page and u view the source you will not see any of the static HTML inside that page. But if i navigate to /about without being redirected in the if statement and i view source i can see all the html. Have you noticed this? Do if statements break the automatic static optimization ?
@leighhalliday
@leighhalliday 3 жыл бұрын
Hey M! Is this causing major issues? I haven't looked into it further but I wouldn't worry about it too much unless it's actually solving issues for your users.
@ravalikag519
@ravalikag519 2 жыл бұрын
Such a relief to finally find something I badly needed ! I still need some help though. Leigh, I am using next js and Link components. On my navigation - ex: there is a link /about and I have redirection rules to redirect it to /about-new. The issue is when I click the link it still loads /about and not /about-new (something to do with how Link and next work but unable to figure out ). But when I explicitly type in /about or just refresh the /about page it gets redirected to /about-new. I need the click to redirect as well Could you please help me ?
@ytPEDROjoao
@ytPEDROjoao 3 жыл бұрын
I needed this tutorial! thanks
@regisnut
@regisnut 3 жыл бұрын
shallow routing is kind the persist State in react-router, right? many thanks and what about pathname? params? thanks is it similar to react-router?
@leighhalliday
@leighhalliday 3 жыл бұрын
Yup! It's pretty similar... you can access path/params from the router.
@creative-commons-videos
@creative-commons-videos 3 жыл бұрын
Hi why my nextjs app navigation takes time, is it default behaviour or am i doing something wrong ? i can literally count up to 3 after clicking on any links, and seems like nothing happened but after 3 to 4 seconds i can see it transit to clicked page !!!
@marlonj.remediosgonzalez737
@marlonj.remediosgonzalez737 3 жыл бұрын
I have the same issue, was you able to fixed?
@creative-commons-videos
@creative-commons-videos 3 жыл бұрын
@@marlonj.remediosgonzalez737 yes, it is just a default behaviour it's actually prerendering data from api before navigation, so you might need to add some global indicator on routechangeevent
@marlonj.remediosgonzalez737
@marlonj.remediosgonzalez737 3 жыл бұрын
@@creative-commons-videos Thanks so much for your quick anwser, could you help me with some example how can I do that? thanks in advance
@creative-commons-videos
@creative-commons-videos 3 жыл бұрын
@@marlonj.remediosgonzalez737 Router.events.on("routeChangeStart", () => { NProgress.start(); }); Router.events.on("routeChangeComplete", () => { NProgress.done(); });
@creative-commons-videos
@creative-commons-videos 3 жыл бұрын
use this library nprogress and above code on root component, _app.tsx
@nategage7180
@nategage7180 4 жыл бұрын
Hi Leigh, love the thumbnail ;) If I had a component that had a list of cities, and when I clicked on a city, it rendered a list of sports teams (for example) from that city. Now if each of those sports teams were linkable to another url, how would Next.js handle redirecting back to the previous page but still have that city's sports teams pre-selected? Not sure if that makes sense, but I can't find any resources on this anywhere!
@silenux7419
@silenux7419 4 жыл бұрын
Maybe you could store that state linked with query params. So when you redirect back the useEffect kicks in and loads your previous state.
@nategage7180
@nategage7180 4 жыл бұрын
That’s a good idea, I’ll give that a go!
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Nate! I think you have two options... the first is to store your state within query parameters of the URL like I did in this video... or you can store it in localStorage similar to the custom hook I built in this video: kzbin.info/www/bejne/bWW3mZZ8aq-ksLc
@adamtak3128
@adamtak3128 4 жыл бұрын
I use the Redirect component with my auth state. If the user isn’t logged in, I redirect them to the login page. Would you say that’s also a good way is using something like this?
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Adam! Yes! I think so.
@muhammadshahnewaz2787
@muhammadshahnewaz2787 3 жыл бұрын
How can I hide the empty object without a spinner?
@leighhalliday
@leighhalliday 3 жыл бұрын
I think you can just render null, or can add a "hidden" attribute to your HTML.
@hbela1000
@hbela1000 2 жыл бұрын
Excellent, thx.
@ferrad1
@ferrad1 4 жыл бұрын
Hey Leigh loved this video as always I would very much appreciate it if you could make a video about internationalization with nextjs 10 including a language switcher component to go from one language to another. Thank you
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Ferrad! That's a great suggestion... thank you! I'll try to cover that in the future.
@ferrad1
@ferrad1 4 жыл бұрын
@@leighhalliday Thank you very much sir
@kaisian4940
@kaisian4940 4 жыл бұрын
Hi, can you do a video about route changing confirmation? For example, when the form is dirty, I want to show the confirmation dialog when the user is navigating to other routes :D
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Kai! Great suggestion... I'll add it to my list of potential videos.
@chamir4614
@chamir4614 4 жыл бұрын
Great video dude, thx you :)
@leighhalliday
@leighhalliday 4 жыл бұрын
You're very welcome, Chamir!
@ericksonmanuelholguin2776
@ericksonmanuelholguin2776 4 жыл бұрын
best redirect ssr
@leighhalliday
@leighhalliday 4 жыл бұрын
Thanks Erickson!
@TheLionelgamer
@TheLionelgamer 3 жыл бұрын
Thanks teacher! Hahaha
@leighhalliday
@leighhalliday 3 жыл бұрын
Haha, any time!
@livestreamer5478
@livestreamer5478 4 жыл бұрын
Why nobody makes a video on doing it with more links, and seeing whether the scroll position is maintained?🤫
@leighhalliday
@leighhalliday 4 жыл бұрын
Leaving this video for you to do my friend :)
@godwinebikwo6544
@godwinebikwo6544 4 жыл бұрын
Leigh Halliday always on holiday getting that shmoney on payday offering us gems every other day 😅
@leighhalliday
@leighhalliday 4 жыл бұрын
Haha... trying to produce high quality content! :)
@shy6892
@shy6892 3 жыл бұрын
iphone notch haircut
Improving SEO with (Dynamic) Sitemaps in Next.js
17:29
Leigh Halliday
Рет қаралды 38 М.
Introduction to Next.js 10's Internationalized (i18n) Routing
14:07
Leigh Halliday
Рет қаралды 8 М.
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
Next.js 10's New Image Component
15:19
Leigh Halliday
Рет қаралды 12 М.
Clean Architecture in Next.js: A Complete Implementation Guide
53:07
Self-Hosting Next.js
45:13
leerob
Рет қаралды 78 М.
Next.js App Router REVIEW (Six Months In Prod)
16:10
Theo - t3․gg
Рет қаралды 61 М.
Is Next.js 15 any good? "use cache" API first look
8:16
Beyond Fireship
Рет қаралды 127 М.
CSR, SSR, and SSG on NextJS
25:13
Jack Herrington
Рет қаралды 49 М.
Charging Money with Stripe in Next.js in 15 Minutes
18:22
Leigh Halliday
Рет қаралды 10 М.
I built the same app 10 times // Which JS Framework is best?
21:58
Fireship
Рет қаралды 2,6 МЛН