👍🏾 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.
@leighhalliday4 жыл бұрын
Thanks, Richard! I actually didn't use a cleanup function in this example... the `return null` was from the Redirect component itself.
@sheldonfourie59594 жыл бұрын
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
@leighhalliday4 жыл бұрын
Thanks Sheldon! New course coming next week hopefully :)
@samdimahmood90474 жыл бұрын
This was a great video! Hoping to see a video on dynamic routing soon!
@leighhalliday4 жыл бұрын
Hey Samira! I'll make sure to cover it at some point in the future :)
@jpbm63693 жыл бұрын
That redirect component safe lives, thank you.
@leighhalliday3 жыл бұрын
Haha nice, glad it helped!!
@silenux74194 жыл бұрын
Excellent video Leigh. Loving Nextjs, it surpassed Gatsby and it's my default react framework.
@leighhalliday4 жыл бұрын
Thank you Silenux! Me too :) Loving Next.js.
@rvmyangalstar20242 жыл бұрын
Excellent explanation 👌👌👌👌
@leighhalliday2 жыл бұрын
Thank you Jagan!!
@NorbyWinner4 жыл бұрын
👍 excellent explanation, as usual
@leighhalliday4 жыл бұрын
Thank you very much, Norb!
@kunglane4 жыл бұрын
Best Next.js explanations on YT 😀👍 THANKS
@leighhalliday4 жыл бұрын
Thanks S OG!! I appreciate it.
@hanfriednguegan83213 жыл бұрын
Hey Leigh what can i do when i want to pass a state from one component to another when i use history.push() ?
@ricardovannoort2 жыл бұрын
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?
@syz39813 жыл бұрын
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 ?
@leighhalliday3 жыл бұрын
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.
@ravalikag5192 жыл бұрын
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 ?
@ytPEDROjoao3 жыл бұрын
I needed this tutorial! thanks
@regisnut3 жыл бұрын
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?
@leighhalliday3 жыл бұрын
Yup! It's pretty similar... you can access path/params from the router.
@creative-commons-videos3 жыл бұрын
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.remediosgonzalez7373 жыл бұрын
I have the same issue, was you able to fixed?
@creative-commons-videos3 жыл бұрын
@@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.remediosgonzalez7373 жыл бұрын
@@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
use this library nprogress and above code on root component, _app.tsx
@nategage71804 жыл бұрын
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!
@silenux74194 жыл бұрын
Maybe you could store that state linked with query params. So when you redirect back the useEffect kicks in and loads your previous state.
@nategage71804 жыл бұрын
That’s a good idea, I’ll give that a go!
@leighhalliday4 жыл бұрын
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
@adamtak31284 жыл бұрын
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?
@leighhalliday4 жыл бұрын
Hey Adam! Yes! I think so.
@muhammadshahnewaz27873 жыл бұрын
How can I hide the empty object without a spinner?
@leighhalliday3 жыл бұрын
I think you can just render null, or can add a "hidden" attribute to your HTML.
@hbela10002 жыл бұрын
Excellent, thx.
@ferrad14 жыл бұрын
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
@leighhalliday4 жыл бұрын
Hey Ferrad! That's a great suggestion... thank you! I'll try to cover that in the future.
@ferrad14 жыл бұрын
@@leighhalliday Thank you very much sir
@kaisian49404 жыл бұрын
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
@leighhalliday4 жыл бұрын
Hey Kai! Great suggestion... I'll add it to my list of potential videos.
@chamir46144 жыл бұрын
Great video dude, thx you :)
@leighhalliday4 жыл бұрын
You're very welcome, Chamir!
@ericksonmanuelholguin27764 жыл бұрын
best redirect ssr
@leighhalliday4 жыл бұрын
Thanks Erickson!
@TheLionelgamer3 жыл бұрын
Thanks teacher! Hahaha
@leighhalliday3 жыл бұрын
Haha, any time!
@livestreamer54784 жыл бұрын
Why nobody makes a video on doing it with more links, and seeing whether the scroll position is maintained?🤫
@leighhalliday4 жыл бұрын
Leaving this video for you to do my friend :)
@godwinebikwo65444 жыл бұрын
Leigh Halliday always on holiday getting that shmoney on payday offering us gems every other day 😅
@leighhalliday4 жыл бұрын
Haha... trying to produce high quality content! :)