0

Is there any way to change URL without reloading in NodeJS as like this site?

Prakash Pazhanisamy
  • 997
  • 1
  • 15
  • 25
  • 3
    Can you be more specific? – Abhyudit Jain Oct 14 '17 at 12:23
  • Please go to this site: http://md-pro-angular.creative-tim.com. It is developed in AngularJS. In this site, when clicking on the menu it is redirecting to some other URL without reloading. Like this, is there any way in NodeJS? – Prakash Pazhanisamy Oct 14 '17 at 12:28
  • It is not a duplicate. I am asking in NodeJS. @stdob – Prakash Pazhanisamy Oct 14 '17 at 12:40
  • 1
    Please be more specifc and share your code. Also [read this article](https://stackoverflow.com/help/mcve) on how to write a minimal, complete and verifiable example. – lumio Oct 14 '17 at 12:43
  • [fragment Identifier](http://www.html5-tutorials.org/html-basics/links/) could be a good way... In case you want to have a complete good looking URL.. **check my posts in the Answers Below** – Rohit Kumar Oct 14 '17 at 13:30

2 Answers2

2

Assuming that you are aware #abc in URL methods & dont want to use the Hashchange event..

In that case

npm history is exactly what you are looking for :) here is a use case

you can change the html body & then change the URL without any page reload

for e.g. suppose you have a "/characters" . you can res.send() & do some action after that you can do something like..

history.pushState(null, '/characters/');

this will add a /characters to the end of your current URL without reloading the page

Rohit Kumar
  • 1,777
  • 2
  • 13
  • 26
1

The effect you are describing sounds like a SPA (Single-Page Application).

(SPAs) are Web apps that load a single HTML page and dynamically update that page as the user interacts with the app

The site you reference is using Angular. The server behind it may or may not be using Node. But in either case you would not be using Node to achieve this kinds of effect.

Angular has its own internal routing, it is an optional service that is used to present a particular component view for a given URL without refreshing the page.

The most common case of using Node with these kinds of frameworks is having Node serve static html page. In this case that would be angular's index.html page. Any other routing would be done internally using angular.

Hope this helped you in some way.

Andresson
  • 1,257
  • 10
  • 15