Very nice tutorial both part 1 and 2! I have understood quite well. I have a few questions though: 1. How to add a loading progress in case a view takes longer to be loaded 2. How to load a view which has some custom scripts and CSS files links in it Answers to these two questions will be much appreciated @dcode
This is probably the most well done/explained video tutorial about SPA I've found in 2020. It's worth to mention the difference of how JS is processed on frontend JS files when compared with the server.js file (stuff such as require, etc). It would be also cool if you could do PWA integration (storage/websql). Keep up with the awesome work!
These 2 videos were great. I would love to see a continuation with the following: 1) pulling the HTML from there server using Fetch and a loading overlay and 2) rendering a 404 view for invalid routes. Or at the very least redirect back to Dashboard when the route is invalid.
This is great! I've been learing react but for academic reasons I was working on a static site with alpinejs that uses the fetch api with laravel sanctum. After several frustrating days I managed a successful login but it is still just a static site. I think with all I learned from you I can move forward and make it an actual SPA. Thank you!
Great video and excellent teacher, for understanding how react works under the hood you leaves me feeling a little wiser. Ive one problem after following along. Dont want to just use your free code to understand why and how the problem exists. Everything is working exactly how should do apart from sometimes or mostly all times when traversing between links, the page is refreshing. Anyone?
Great video series, tks!!! One question: why don't we consider building the URLs with queries as "/posts?id=2&dcode=35" instead of "/posts/2/35" ? It'd be much clearer and easy to parse! Is there a definite reason why it's best not to use queries on SPA URLs?
I'm trying to loop through an array of restaurant menu items (Posts) and dynamically generate a unique item details page (PostView) for each item rather than manually creating a PostView file for each item and was wondering if you could point me in the right direction for learning how to best implement this. This begs the question -- have you considered making a part 3 to this series of tutorials?
Great tutorial! The regex stuff is a bit over my head currently but you explained everything else clearly enough that I got a good overall idea of how it all works. Thanks for the video!
@@dcode-software Very nice tutorial both part 1 and 2! I have understood quite well. I have a few questions though: 1. How to add a loading progress in case a view takes longer to be loaded 2. How to load a view which has some custom scripts and CSS files links in it Answers to these two questions will be much appreciated @dcode
Very informative videos (both 1 & 2)! I do have 1 question (and it might be a stupid one), how do you go about adding an actual post (like the ones shown at the beginning of this video)? (please excuse the beginner in me!)
Now this has some clever stuff in it. I've always wondered but never actually looked into a client side routing engine before. Really good informative video and a nice solution. I didn't quite understand why right at the end you threw in that [location.pathname]? Seemed a bit rushed for no reason.
Thanks for the tutorial , the first video was great . I just wish you didn;t get into the Regex area of it because it felt too advanced for the kind of people (me included) who are just starting off .
Hi, I love the two SPA videos, but I get stock. How I access the individual posts having a link on the Posts page? Do I need to create an individual file for each post? how?
Hi. I'm getting a strange behavior. If I insert a link inside the HTML returned by PostView.js, clicking on it shows the post as expected. However, if I enter the same URL localhost:5060/posts/23/4 in the address bar and hit enter, I still get one post displayed, but without any styling. When I look at the index.css returned in the Dev Tools, it has the contents that we put in index.html, instead. Any idea why this is happening?
Hey buddy I fixed this issue in the end. It was due to the folder path syntax. instead of using just static/css/index.css for the href in the style sheet. re. begin the file path with ../ example
How might you extends your framework to handle form input when each view could have its own form? Maybe each post could allow for a user to add a comment?
@@dcode-software Very nice tutorial both part 1 and 2! I have understood quite well. I have a few questions though: 1. How to add a loading progress in case a view takes longer to be loaded 2. How to load a view which has some custom scripts and CSS files links in it Answers to these two questions will be much appreciated @dcode
Why switching between dashboard posts and settings does not work for me, the dashboard will show, but when I press posts or settings it will show cannot get / posts or / settings. Thank you for support.
Hi and thanks for the great vid! I learned a lot in this tutorial :) But I have one problem with my code. If i try to access to the /posts/:id route in my browser search bar I get a MIME Type error. If I am accessing it via link tag in my html it works totally fine. What could be a potential mistake I did?
"Some people, when confronted with a problem, think ‘I know, I’ll use regular expressions.’ Now they have two problems." - Jamie Zawinski But for those confused, Dom has a good video on RegEx at ruclips.net/video/ArxOzeAONHg/видео.html
@@dcode-software Very nice tutorial both part 1 and 2! I have understood quite well. I have a few questions though: 1. How to add a loading progress in case a view takes longer to be loaded 2. How to load a view which has some custom scripts and CSS files links in it Answers to these two questions will be much appreciated @dcode
With a few tweaks it can be made easier to understand and more compact we have as in the code const pathToRegexForValues = (path) => new RegExp('^' + path.replace(/\//g, '\\/').replace(/:\w+/g, '(.+)') + '$'); and we can define const pathToRegexForKeys = (path) => new RegExp('^' + path.replace(/\//g, '\\/').replace(/:\w+/g, ':(.+)') + '$'); which does almost the same but leaves out the : from the regExpression with the intention to capture just the name So now when we match we have return { route: route, matchedParamValues: location.pathname.match( pathToRegexForValues(route.path) ), // this is the same matchedParamKeys: route.path.match(pathToRegexForKeys(route.path)), // here we go the path we are looking for '/posts/:id' and extract everything after the : // for each occurence of : }; Everything else is the same. Now we go to the getParams function and we will have values = match.matchedParamsValues.slice(1) ; // since we renamed result to matchedParamValues keys = match.matchedParamsKeys.slice(1) ; and everything else stays the same.
What if you need integration with a database? How will you manage both client and server-side? It can't be an app if it does not have any dynamic content
This is perfect tutorial for me! But I have an issue. My router works fine, but when I switch the page to postView, css isn't being applied at all. Does anyone know about this issue?!
@@mingmeng030 I actually figured it out. It was the syntax for me with the link ref for the style sheet. I had to use ../ at the start of the file path. Instead of just static/css/.index.css try ../static/css/index.css
Thoroughly enjoyed this video and found it very helpful thankyou. I did get stuck however with the pathToRegex. I get the following error when I try to go to localhost:5500/posts/2 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec. did anyone come across this ISSUE SORTED ALL GOOD
Hi Dom sorry to bother mate but I have a bit of an issue, can you help? I built a SPA just like yours but now I face the deployment problem, now, how can I deploy a SPA just like the one you build on netlify or heroku? My problem is that the app has a backend where the routes are and the app needs it in order to hit the routes, i deployed all the files to netlify and heroku but no good, what to do? If anyone besides Dom in here knows please help me I am at lost.
I've been making a site with this SPA method, and the solution is actually quite easy, after you run the router function on after the dom has loaded, you just need to run a function to apply your event listeners to current page, you can even pass the current path through the new function as a parameter to only load certain event listeners depending on the view you are loading!
@@casm101 any chance you could tell me more how you handled the event listeners? I've been building a site with this method also and I'm am struggling with the event listeners for the views.
@@devindickerson9699 Hi, of course! I did it the following way: I have a separate file where I manage ONLY event listeners (for comodity, but you don't have to) and all the listeners are wrapped in a window.onload function to make sure they execute when everything is available, and inside I separate my listeners in groups that check if they correspond to the current site path, if so, they run, if not, they don't! Another way is to check if the element you wish to apply the listener to is visible on screen or not, which may be a better technically, depending on your application... Sorry for the late reply
@@casm101 any chance of sharing the code you wrote for passing event listeners to the current page, I'm getting stuck trying to wrap my code in a window onload event function. I am still learning JS,. I keep on getting ye old 'cannot read properties of null'?
Actually I fixed the Null reading error. for the window event listener. Though I am stuck on how pass the page path through so the click event wrapped inside works THIS IS my Code for handling the event I a huge Noobie. NAy help could be appreciated. window.addEventListener("onload", () => {
Very Informative video . Really very nice concept implemented . I am trying to make a web application referring your video . Thank you for the video . Trying to implement there's a problem came in front of me , When I navigate to dashboard/0 , the address of all static files changes . Mean to say , when the url is 'localhost:5000/dashboard/0' , then Images , css files which are having path 'localhost:5000/static/images/abc.png' changes to 'localhost:5000/dashboard/static/images/abc.png' , hence image doesn't displays in 'localhost:5000/dashboard/0' page . I just wanted to know , why this is happening ?
I came up with another question If you don't mind , I wants to know how to deploy this app on firebase . Having server.js and index.js both running . I hosted it on firebase the simple way any normal website is hosted . And after hosting it I found that index.js is running and server.js file is not running because redirecting after login failed which should reach to server.js . Instead 404.html is called . Observing this I can say that server.js is not running . How to host the application such a way that server.js should run along with index.js ?
Hi , I am having problem in loading multiple HTML pages . Can you please help me. Is there any possibility of connecting with you via google meet. Pleaseeeee
Hi and thanks for the great vid! I learned a lot in this tutorial :) But I have one problem with my code. If i try to access to the /posts/:id route in my browser search bar I get a MIME Type error. If I am accessing it via link tag in my html it works totally fine. What could be a potential mistake I did?
Very nice tutorial both part 1 and 2! I have understood quite well. I have a few questions though:
1. How to add a loading progress in case a view takes longer to be loaded
2. How to load a view which has some custom scripts and CSS files links in it
Answers to these two questions will be much appreciated @dcode
Did you find any answer to 2nd question?
i think these are pretty straight forward questions but yo, you've got chat GPT
After all these years of SPA, it finally makes sense how things work under the hood. Great work!
This is probably the most well done/explained video tutorial about SPA I've found in 2020. It's worth to mention the difference of how JS is processed on frontend JS files when compared with the server.js file (stuff such as require, etc). It would be also cool if you could do PWA integration (storage/websql).
Keep up with the awesome work!
Appreciate that! Yes I've got a video on PWA but it could be an idea to combine the two 🤔
Definitely should do it
this tutorial should have thousands of likes. thank you for doing this!
These 2 videos were great. I would love to see a continuation with the following: 1) pulling the HTML from there server using Fetch and a loading overlay and 2) rendering a 404 view for invalid routes. Or at the very least redirect back to Dashboard when the route is invalid.
Watch first part he told us about 404
Changed my life sir, tnx for making this video
Long live js king 👑. This is the ultimate explained video I've found on RUclips
A third part would be nice, in which you connect to mysql, create posts, save posts and delete posts.
1 month, no answer. This channel must be dead. Too bad, i liked it.
This is great! I've been learing react but for academic reasons I was working on a static site with alpinejs that uses the fetch api with laravel sanctum. After several frustrating days I managed a successful login but it is still just a static site. I think with all I learned from you I can move forward and make it an actual SPA. Thank you!
For the pathToRegex function, you could use named capture groups to avoid having to extract the names again from the path in getParams.
What patterns are you using in this vid?
Really really great video. Also a great reminder to finally learn regex, it’s nothing but gibberish to me
Don't worry you still explained it well, Thank you very much for this great tutorial!
Wow this was great! Thanks for the quality tutorial man; absolutely eye opening.
Great video and excellent teacher, for understanding how react works under the hood you leaves me feeling a little wiser. Ive one problem after following along. Dont want to just use your free code to understand why and how the problem exists. Everything is working exactly how should do apart from sometimes or mostly all times when traversing between links, the page is refreshing. Anyone?
Fantastic tutorial! Very good explanation, good design and valuable material. Thank you!
Man we need a full-fledged framework tutorial
Now that could quite possibly be re-inventing the wheel! Haha
@@dcode-software I see nothing wrong here
Great video series, tks!!! One question: why don't we consider building the URLs with queries as "/posts?id=2&dcode=35" instead of "/posts/2/35" ? It'd be much clearer and easy to parse! Is there a definite reason why it's best not to use queries on SPA URLs?
I'm trying to loop through an array of restaurant menu items (Posts) and dynamically generate a unique item details page (PostView) for each item rather than manually creating a PostView file for each item and was wondering if you could point me in the right direction for learning how to best implement this. This begs the question -- have you considered making a part 3 to this series of tutorials?
Great tutorial! The regex stuff is a bit over my head currently but you explained everything else clearly enough that I got a good overall idea of how it all works. Thanks for the video!
Appreciate it! Thanks Kayla great to see you enjoyed
@@dcode-software Very nice tutorial both part 1 and 2! I have understood quite well. I have a few questions though:
1. How to add a loading progress in case a view takes longer to be loaded
2. How to load a view which has some custom scripts and CSS files links in it
Answers to these two questions will be much appreciated @dcode
Simply awesome !
Very informative videos (both 1 & 2)! I do have 1 question (and it might be a stupid one), how do you go about adding an actual post (like the ones shown at the beginning of this video)? (please excuse the beginner in me!)
Very clear and thorough. Thanks! (You move rather quick, so it might be nice to have your mouse cursor highlighted...)
Now this has some clever stuff in it. I've always wondered but never actually looked into a client side routing engine before. Really good informative video and a nice solution.
I didn't quite understand why right at the end you threw in that [location.pathname]? Seemed a bit rushed for no reason.
So you if got an array of posts, you use this to populated the data from the array into the Post view, matching the post by id ?
Yep, pretty much!
Thanks for the tutorial , the first video was great . I just wish you didn;t get into the Regex area of it because it felt too advanced for the kind of people (me included) who are just starting off .
Hi,
I love the two SPA videos, but I get stock.
How I access the individual posts having a link on the Posts page?
Do I need to create an individual file for each post? how?
Hi. I'm getting a strange behavior. If I insert a link inside the HTML returned by PostView.js, clicking on it shows the post as expected. However, if I enter the same URL localhost:5060/posts/23/4 in the address bar and hit enter, I still get one post displayed, but without any styling. When I look at the index.css returned in the Dev Tools, it has the contents that we put in index.html, instead.
Any idea why this is happening?
Hello I have this exact issue Did you figure it out?
In dev tools as well as the index.html being loaded into the index.css the JS folder is not being laoded at all?
Hey buddy I fixed this issue in the end. It was due to the folder path syntax.
instead of using just static/css/index.css for the href in the style sheet. re. begin the file path with ../
example
How might you extends your framework to handle form input when each view could have its own form? Maybe each post could allow for a user to add a comment?
Maybe use Ajax🤔
Thanks! It's just amazing!
All good!
@@dcode-software Very nice tutorial both part 1 and 2! I have understood quite well. I have a few questions though:
1. How to add a loading progress in case a view takes longer to be loaded
2. How to load a view which has some custom scripts and CSS files links in it
Answers to these two questions will be much appreciated @dcode
i have one question. when i go /post/2 that's work but when i refresh the page all css is gone.Why that's happening?
Why switching between dashboard posts and settings does not work for me, the dashboard will show, but when I press posts or settings it will show cannot get / posts or / settings. Thank you for support.
Hi and thanks for the great vid! I learned a lot in this tutorial :)
But I have one problem with my code. If i try to access to the /posts/:id route in my browser search bar I get a MIME Type error. If I am accessing it via link tag in my html it works totally fine. What could be a potential mistake I did?
Great video. How do I consumean api and pass to the view?
"Some people, when confronted with a problem, think ‘I know, I’ll use regular expressions.’ Now they have two problems." - Jamie Zawinski
But for those confused, Dom has a good video on RegEx at ruclips.net/video/ArxOzeAONHg/видео.html
Would i get request and response (req, res) in routes path?
Is it a good practice to use SPA in Vanilla JS ? Looks so much complicated
For small projects, possibly - it's up to you. This is more for learning purposes 😁
@@dcode-software Very nice tutorial both part 1 and 2! I have understood quite well. I have a few questions though:
1. How to add a loading progress in case a view takes longer to be loaded
2. How to load a view which has some custom scripts and CSS files links in it
Answers to these two questions will be much appreciated @dcode
You are awesome! You are master!
With a few tweaks it can be made easier to understand and more compact
we have as in the code
const pathToRegexForValues = (path) =>
new RegExp('^' + path.replace(/\//g, '\\/').replace(/:\w+/g, '(.+)') + '$');
and we can define
const pathToRegexForKeys = (path) => new RegExp('^' + path.replace(/\//g, '\\/').replace(/:\w+/g, ':(.+)') + '$');
which does almost the same but leaves out the : from the regExpression with the intention to capture just the name
So now when we match we have
return {
route: route,
matchedParamValues: location.pathname.match( pathToRegexForValues(route.path) ), // this is the same
matchedParamKeys: route.path.match(pathToRegexForKeys(route.path)),
// here we go the path we are looking for '/posts/:id' and extract everything after the :
// for each occurence of :
};
Everything else is the same. Now we go to the getParams function and we will have
values = match.matchedParamsValues.slice(1) ; // since we renamed result to matchedParamValues
keys = match.matchedParamsKeys.slice(1) ; and everything else stays the same.
What if you need integration with a database? How will you manage both client and server-side?
It can't be an app if it does not have any dynamic content
I am having issues accessing the view pages In the dom. please assist
how can i find Github Repo??
This is perfect tutorial for me!
But I have an issue. My router works fine, but when I switch the page to postView, css isn't being applied at all.
Does anyone know about this issue?!
I have this same issue
Did you find a dix
@@wewiwowo42 not yet,,I searched everywhere but there’s nothing can help me. I think it can be react’s error
@@mingmeng030 I actually figured it out. It was the syntax for me with the link ref for the style sheet. I had to use ../ at the start of the file path. Instead of just static/css/.index.css try ../static/css/index.css
@@wewiwowo42 omg you saved me!! It also worked at my issue!! Thanks:)
@@mingmeng030 awesome.
need tutorial how to run js script and fetch api in page example product.html ?
this video is piece of gold in sea of internet shit, works fine! good foundation!
My page getting error when change route to /about and reload the page
How can i fix this?
Thoroughly enjoyed this video and found it very helpful thankyou. I did get stuck however with the pathToRegex. I get the following error when I try to go to localhost:5500/posts/2
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
did anyone come across this
ISSUE SORTED ALL GOOD
getting the same error, how did you manage to solve it?
Having th same issue. How did you solve it?
Where i can download the code?
HI, great video! But I didn't understand how to add posts. Could you explain? Thanks :)
how many more videos in this series?
As for right now, this is the last one.
Hi Dom sorry to bother mate but I have a bit of an issue, can you help?
I built a SPA just like yours but now I face the deployment problem, now, how can I deploy a SPA just like the one you build on netlify or heroku?
My problem is that the app has a backend where the routes are and the app needs it in order to hit the routes, i deployed all the files to netlify and heroku but no good, what to do?
If anyone besides Dom in here knows please help me I am at lost.
รอ SPA #3
อยากรู้ว่าจะนำข้อมูลจาก data base มาแสดงใน SPA นี้ยังไง
Anyone else has the .matchAll(...).map() is not a function
What the router misses tho: route /posts/:id fully blocks /posts/:id/addComment
how do we handle JS in the views? example click event of a button
I've been making a site with this SPA method, and the solution is actually quite easy, after you run the router function on after the dom has loaded, you just need to run a function to apply your event listeners to current page, you can even pass the current path through the new function as a parameter to only load certain event listeners depending on the view you are loading!
@@casm101 any chance you could tell me more how you handled the event listeners? I've been building a site with this method also and I'm am struggling with the event listeners for the views.
@@devindickerson9699 Hi, of course!
I did it the following way: I have a separate file where I manage ONLY event listeners (for comodity, but you don't have to) and all the listeners are wrapped in a window.onload function to make sure they execute when everything is available, and inside I separate my listeners in groups that check if they correspond to the current site path, if so, they run, if not, they don't!
Another way is to check if the element you wish to apply the listener to is visible on screen or not, which may be a better technically, depending on your application...
Sorry for the late reply
@@casm101 any chance of sharing the code you wrote for passing event listeners to the current page, I'm getting stuck trying to wrap my code in a window onload event function. I am still learning JS,. I keep on getting ye old 'cannot read properties of null'?
Actually I fixed the Null reading error. for the window event listener.
Though I am stuck on how pass the page path through so the click event wrapped inside works THIS IS my Code for handling the event I a huge Noobie. NAy help could be appreciated.
window.addEventListener("onload", () => {
if (route.path === ("/article")) {
const techbtn = document.getElementById("techbtn");
const techinfo = document.getElementById("techinfo");
techbtn.addEventListener("click", () => {
techinfo.classList.remove("nonvisible");
techinfo.classList.add("visible");
});
}
});
Please make a video on passport login using node
Ótimo vídeo parabéns 👏.
Great video. I really hope you can complement this SPA with firebase auth, it will be great. Thanks!!
Very Informative video . Really very nice concept implemented . I am trying to make a web application referring your video . Thank you for the video .
Trying to implement there's a problem came in front of me , When I navigate to dashboard/0 , the address of all static files changes .
Mean to say , when the url is 'localhost:5000/dashboard/0' , then Images , css files which are having path 'localhost:5000/static/images/abc.png' changes to 'localhost:5000/dashboard/static/images/abc.png' , hence image doesn't displays in 'localhost:5000/dashboard/0' page . I just wanted to know , why this is happening ?
I made a video on this a while ago:
ruclips.net/video/fZjKc2kMKYU/видео.html
@@dcode-software Thank you for the reply . I now got understood what I was doing wrong . Thank you .
I came up with another question If you don't mind , I wants to know how to deploy this app on firebase . Having server.js and index.js both running . I hosted it on firebase the simple way any normal website is hosted . And after hosting it I found that index.js is running and server.js file is not running because redirecting after login failed which should reach to server.js . Instead 404.html is called . Observing this I can say that server.js is not running . How to host the application such a way that server.js should run along with index.js ?
Thanks
Hi , I am having problem in loading multiple HTML pages . Can you please help me. Is there any possibility of connecting with you via google meet. Pleaseeeee
awesome
First! YADIGG
looking for anyone who know how to add event listeners to the html in each view
i guess this is not for beginners. regexp part is confusing as hell
finally
Second !!!!!
🙏
Nice vieos.
Sorry but second part is really complicated
All I hear is right here xD
`no framework` NODE JS IS A FRAMEWORK DOGGGG
"new match.route.view" - this is why I prefer typescript. So confusing.
Hi and thanks for the great vid! I learned a lot in this tutorial :)
But I have one problem with my code. If i try to access to the /posts/:id route in my browser search bar I get a MIME Type error. If I am accessing it via link tag in my html it works totally fine. What could be a potential mistake I did?
Great video. I really hope you can complement this SPA with firebase auth, it will be great. Thanks!!