JSFiddle - React, Tailwind, and code Playground

by moob

HTML

<a href="#one">one</a> 
<a href="#two">two</a> 
<a href="#three">three</a> 
<a href="#four">four</a> 
<a href="#five">five</a> 

<button>back</button>

JavaScript

var app = {
    history : {
        histarry : [],
        add : function(loc){
            var arr = app.history.histarry;
            //if loc is not already the last item in the histarry
            if(arr[arr.length-1] != loc){
                alert("add "+loc);
                app.history.histarry.push(loc);
            }
        },
        back : function(){
            //up the array else home
            prev = app.history.histarry.pop() || "#home";
            alert("remove "+prev);
        }
    }
};
$("a").on("click",function(e){
    e.preventDefault();
    var loc = $(this).attr("href");
    app.history.add(loc);
});
$("button").on("click",function(e){
    e.preventDefault();
    app.history.back();
});