Okay, but what if we want to add some authentication? What if not every page is supposed to be seen by everybody? Well, let's go back a little bit to our base file, and in this case, we will have the beforeload option, and here I'm doing a request to the server, and in this case, I'm using TRPC, but we could be using a access or fetch request, and if the CD doesn't exist, or it doesn't have the necessary rules for this page, then we throw a redirect to the home page. Here we can do, if the user isn't authenticated, and that all stuff, and this happens before the page is being served to the client, which means it doesn't flash the CD's page, the list of CD's page, and then we'll go through directly to the home page, it doesn't flash anything, which leads to a better user experience.
Okay, now let's talk about the side life of HANA Montana. What if I want to make the user be in one page but seeing another? How can we do that? Okay, so this link component is also from TimeStack Router, and we can say that it goes to the slash mask page, but actually what the user sees is that it's going to the slash CD's page, which I think is pretty cool, and it can become handy when you're opening models and stuff, but you don't want to show the user that it's a different page. And isn't this pure magic?
Okay, now smart data fetching. Now data. This is where TimeStack DNA really kicks in. Each route can have its loader, and here I'm using the loader dependencies to pass the page, so if we needed the page to get our first CD, we could use it in the request. And before rendering my page, I'm doing a request to the server in the loader, again through the IRPC and returning that same result and its search parameters. In order to use the search parameters in the loader, we have to return the loader dependencies in the loader dependencies option. And how can we do this, and how can we use this in the component? Again, with a hook, with the use loader data. And here you get directly the CD, which is loaded already, and guess what? This is also typed with the part before, and we can use the information to our will. And if this wasn't enough, we can also defer data.
Comments