Adding Client Side URL Params - Build a Single Page Application with JavaScript (No Frameworks)

Поделиться
HTML-код
  • Опубликовано: 31 дек 2024

Комментарии • 120

  • @netlity5532
    @netlity5532 3 года назад +13

    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

    • @मेबीराज
      @मेबीराज 2 года назад +1

      Did you find any answer to 2nd question?

    • @chubbyBunny94
      @chubbyBunny94 Год назад

      i think these are pretty straight forward questions but yo, you've got chat GPT

  • @AyushSinghxda
    @AyushSinghxda 3 года назад +3

    After all these years of SPA, it finally makes sense how things work under the hood. Great work!

  • @flexDevelop
    @flexDevelop 4 года назад +28

    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!

    • @dcode-software
      @dcode-software  4 года назад +5

      Appreciate that! Yes I've got a video on PWA but it could be an idea to combine the two 🤔

    • @fellipelorram4341
      @fellipelorram4341 3 года назад +1

      Definitely should do it

  • @ginanjarseladipura3980
    @ginanjarseladipura3980 4 года назад

    this tutorial should have thousands of likes. thank you for doing this!

  • @slackergeek2007
    @slackergeek2007 3 года назад +5

    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.

  • @amirhosseinveysi9546
    @amirhosseinveysi9546 3 года назад +1

    Changed my life sir, tnx for making this video

  • @atleast_me
    @atleast_me 3 года назад +1

    Long live js king 👑. This is the ultimate explained video I've found on RUclips

  • @braddockbrawler
    @braddockbrawler 7 месяцев назад +3

    A third part would be nice, in which you connect to mysql, create posts, save posts and delete posts.

    • @braddockbrawler
      @braddockbrawler 6 месяцев назад

      1 month, no answer. This channel must be dead. Too bad, i liked it.

  • @ThaRealIansanity
    @ThaRealIansanity 2 года назад

    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!

  • @kamoroso94
    @kamoroso94 10 месяцев назад

    For the pathToRegex function, you could use named capture groups to avoid having to extract the names again from the path in getParams.

  • @vuejs1
    @vuejs1 Год назад +1

    What patterns are you using in this vid?

  • @Jangeroo
    @Jangeroo 4 года назад +8

    Really really great video. Also a great reminder to finally learn regex, it’s nothing but gibberish to me

  • @Rm-ey8xe
    @Rm-ey8xe 4 года назад +1

    Don't worry you still explained it well, Thank you very much for this great tutorial!

  • @brandonjaus494
    @brandonjaus494 4 года назад

    Wow this was great! Thanks for the quality tutorial man; absolutely eye opening.

  • @vernatley221
    @vernatley221 2 года назад

    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?

  • @socialpeople6615
    @socialpeople6615 2 года назад

    Fantastic tutorial! Very good explanation, good design and valuable material. Thank you!

  • @amguruprasath8037
    @amguruprasath8037 4 года назад +3

    Man we need a full-fledged framework tutorial

    • @dcode-software
      @dcode-software  4 года назад +2

      Now that could quite possibly be re-inventing the wheel! Haha

    • @arshiagholami7611
      @arshiagholami7611 3 года назад

      @@dcode-software I see nothing wrong here

  • @gustavoexel
    @gustavoexel 4 года назад +6

    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?

  • @jeffreyclaybrook
    @jeffreyclaybrook Год назад

    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?

  • @yumdiddlyum
    @yumdiddlyum 4 года назад +3

    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
      @dcode-software  4 года назад

      Appreciate it! Thanks Kayla great to see you enjoyed

    • @netlity5532
      @netlity5532 3 года назад

      @@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

  • @2005Azm
    @2005Azm 4 года назад +1

    Simply awesome !

  • @fomofonk
    @fomofonk 2 года назад +2

    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!)

  • @blarvinius
    @blarvinius 4 года назад +2

    Very clear and thorough. Thanks! (You move rather quick, so it might be nice to have your mouse cursor highlighted...)

  • @robwatson826
    @robwatson826 3 года назад

    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.

  • @AleksandarIvanov69
    @AleksandarIvanov69 4 года назад +1

    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 ?

  • @compsguru
    @compsguru 2 года назад

    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 .

  • @arqasr
    @arqasr 2 года назад

    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?

  • @05060024
    @05060024 2 года назад +1

    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?

    • @wewiwowo42
      @wewiwowo42 2 года назад

      Hello I have this exact issue Did you figure it out?

    • @wewiwowo42
      @wewiwowo42 2 года назад

      In dev tools as well as the index.html being loaded into the index.css the JS folder is not being laoded at all?

    • @wewiwowo42
      @wewiwowo42 2 года назад

      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

  • @Mickey_McD
    @Mickey_McD 3 года назад +1

    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?

  • @russianstan
    @russianstan 4 года назад +1

    Thanks! It's just amazing!

    • @dcode-software
      @dcode-software  4 года назад +1

      All good!

    • @netlity5532
      @netlity5532 3 года назад +1

      @@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

  • @shvrolet
    @shvrolet Год назад

    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?

  • @nicolaschvostal
    @nicolaschvostal 2 года назад

    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.

  • @marcelm7661
    @marcelm7661 Год назад

    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?

  • @chimsgraphic
    @chimsgraphic 3 года назад

    Great video. How do I consumean api and pass to the view?

  • @koitaki
    @koitaki 3 года назад +2

    "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

  • @youmee8956
    @youmee8956 3 года назад

    Would i get request and response (req, res) in routes path?

  • @Thanveershah
    @Thanveershah 4 года назад +1

    Is it a good practice to use SPA in Vanilla JS ? Looks so much complicated

    • @dcode-software
      @dcode-software  4 года назад +3

      For small projects, possibly - it's up to you. This is more for learning purposes 😁

    • @netlity5532
      @netlity5532 3 года назад +1

      @@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

  • @ГеоргиЧавдаров-в7з
    @ГеоргиЧавдаров-в7з 4 года назад

    You are awesome! You are master!

  • @KostasOreopoulos
    @KostasOreopoulos 4 года назад

    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.

  • @iglesiasleonardo1742
    @iglesiasleonardo1742 2 года назад

    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

  • @olutolamoses4416
    @olutolamoses4416 3 года назад

    I am having issues accessing the view pages In the dom. please assist

  • @mohamedshehata3979
    @mohamedshehata3979 Год назад

    how can i find Github Repo??

  • @mingmeng030
    @mingmeng030 2 года назад +1

    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?!

    • @wewiwowo42
      @wewiwowo42 2 года назад

      I have this same issue
      Did you find a dix

    • @mingmeng030
      @mingmeng030 2 года назад

      @@wewiwowo42 not yet,,I searched everywhere but there’s nothing can help me. I think it can be react’s error

    • @wewiwowo42
      @wewiwowo42 2 года назад

      @@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

    • @mingmeng030
      @mingmeng030 2 года назад +1

      @@wewiwowo42 omg you saved me!! It also worked at my issue!! Thanks:)

    • @wewiwowo42
      @wewiwowo42 2 года назад

      @@mingmeng030 awesome.

  • @hartono9583
    @hartono9583 Год назад

    need tutorial how to run js script and fetch api in page example product.html ?

  • @vladosononame6376
    @vladosononame6376 3 года назад

    this video is piece of gold in sea of internet shit, works fine! good foundation!

  • @maheshYchhetri
    @maheshYchhetri 3 года назад

    My page getting error when change route to /about and reload the page
    How can i fix this?

  • @wewiwowo42
    @wewiwowo42 2 года назад

    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

    • @daredevil_37
      @daredevil_37 2 года назад

      getting the same error, how did you manage to solve it?

    • @rogerchan548
      @rogerchan548 Год назад

      Having th same issue. How did you solve it?

  •  3 года назад

    Where i can download the code?

  • @amezan7777
    @amezan7777 3 года назад

    HI, great video! But I didn't understand how to add posts. Could you explain? Thanks :)

  • @amguruprasath8037
    @amguruprasath8037 4 года назад +1

    how many more videos in this series?

    • @dcode-software
      @dcode-software  4 года назад +1

      As for right now, this is the last one.

  • @mr.o5577
    @mr.o5577 3 года назад

    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.

  • @5ikronoz
    @5ikronoz 4 года назад

    รอ SPA #3
    อยากรู้ว่าจะนำข้อมูลจาก data base มาแสดงใน SPA นี้ยังไง

  • @urekmazino2086
    @urekmazino2086 2 года назад +1

    Anyone else has the .matchAll(...).map() is not a function

  • @Jangeroo
    @Jangeroo 4 года назад

    What the router misses tho: route /posts/:id fully blocks /posts/:id/addComment

  • @richardprakash4630
    @richardprakash4630 3 года назад

    how do we handle JS in the views? example click event of a button

    • @casm101
      @casm101 3 года назад

      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!

    • @devindickerson9699
      @devindickerson9699 2 года назад

      @@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.

    • @casm101
      @casm101 2 года назад

      @@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

    • @wewiwowo42
      @wewiwowo42 2 года назад

      @@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'?

    • @wewiwowo42
      @wewiwowo42 2 года назад

      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");
      });
      }
      });

  • @_.sunnyraj._
    @_.sunnyraj._ 4 года назад

    Please make a video on passport login using node

  • @romuloalves9349
    @romuloalves9349 4 года назад

    Ótimo vídeo parabéns 👏.

  • @aguileraq
    @aguileraq 4 года назад

    Great video. I really hope you can complement this SPA with firebase auth, it will be great. Thanks!!

  • @adityamalviya5113
    @adityamalviya5113 3 года назад

    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 ?

    • @dcode-software
      @dcode-software  3 года назад

      I made a video on this a while ago:
      ruclips.net/video/fZjKc2kMKYU/видео.html

    • @adityamalviya5113
      @adityamalviya5113 3 года назад

      ​@@dcode-software Thank you for the reply . I now got understood what I was doing wrong . Thank you .

    • @adityamalviya5113
      @adityamalviya5113 3 года назад

      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 ?

  • @erfelipe
    @erfelipe 3 года назад

    Thanks

  • @anjanspace
    @anjanspace 4 года назад

    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

  • @rangabharath4253
    @rangabharath4253 4 года назад +1

    awesome

  • @KostaTsourdalakis
    @KostaTsourdalakis 4 года назад +1

    First! YADIGG

  • @devindickerson9699
    @devindickerson9699 2 года назад

    looking for anyone who know how to add event listeners to the html in each view

  • @zakur0hako
    @zakur0hako 3 года назад

    i guess this is not for beginners. regexp part is confusing as hell

  • @braswelljr
    @braswelljr 4 года назад +1

    finally

  • @_.sunnyraj._
    @_.sunnyraj._ 4 года назад +1

    Second !!!!!

  • @yashrajjaiswal9941
    @yashrajjaiswal9941 2 года назад

    🙏

  • @heruhailiuhuang533
    @heruhailiuhuang533 2 года назад

    Nice vieos.

  •  3 года назад +1

    Sorry but second part is really complicated

  • @ashiqurrahmantahmid9634
    @ashiqurrahmantahmid9634 3 года назад

    All I hear is right here xD

  • @remco_smits
    @remco_smits 3 года назад

    `no framework` NODE JS IS A FRAMEWORK DOGGGG

  • @christianf7740
    @christianf7740 3 года назад

    "new match.route.view" - this is why I prefer typescript. So confusing.

  • @tangkasr2132
    @tangkasr2132 Год назад

    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?

  • @aguileraq
    @aguileraq 4 года назад

    Great video. I really hope you can complement this SPA with firebase auth, it will be great. Thanks!!