Problem with url

Asked

Viewed 41 times

0

I made a page where all the content is in it (there are no other pages). I had to adapt a kind of user-friendly url to it, because by clicking on the page sections, the cursor goes to a certain point. It is working correctly, but is a # in the url.

$("a.menu__item").on('click', function(event) {

  if (this.hash !== "") {

    event.preventDefault();

    var hash = this.hash;

    $('html, body').animate({
      scrollTop: $(hash).offset().top
    }, 800, function() {

      window.location.hash = hash;

    });
  }
});

I managed to get the #

$("a.menu__item").on('click', function(event) {

  if (this.hash !== "") {

    event.preventDefault();

    var hash = this.hash;

    $('html, body').animate({
      scrollTop: $(hash).offset().top
    }, 800, function() {

      history.pushState(null, null, 'a.menu__item');
      if (history.pushState) {
        var url_a = hash.substring(1, hash.length);
        history.pushState(null, null, url_a);
      } else {
        location.hash = url_a;
      }
    });
  }
});

However, if I open the page in client/blog, it says that the page does not exist. It would be better to leave the # or it is plausible some idea for the problem of opening the page and it does not exist?

  • 6

    Friend the # is to specify that what you are looking for is inside the html page itself, if you take the # the browser will look for a file with that name and consequently will return 404(not found) if you did everything inside your page the ideal is to leave the # in the url.

  • Got it. I needed some more idea. I’ll leave it then. Thank you very much.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.