I'm going to show you how to set up a simple SPA in React with react-router-dom, and pull in data dynamically through the URL. ![]() This website also happens to be a Single Page Application (or SPA) - only one page is loaded, and every click to a new page loads some additional JSON data, but does not actually request a new resource like loading index.html and about-me.html would. Once it gets to the template, it can pull from the URL to know which variables to display - for example, JavaScript or CSS related posts. ![]() I'm not actually making a folder called categories and filling it with a bunch of files like javascript.html or css.html, I just have one template and the router knows to direct to the proper template. The routes for these pages look something like this: If you go to /categories/javascript or /categories/css, you end up on a category listing page. If you go to /me, you're redirected to my about me page. ![]() (If you know what routing is, feel free to skip this section.)Įxample: If you go to, you end up on my home page. Routing is how a web applications direct traffic. React doesn't come with a built-in router, but we can easily achieve routing with the react-router-dom library.
0 Comments
Leave a Reply. |