JSFiddle - React, Tailwind, and code Playground

JavaScript

const FULL_PATH_LEN = 24;

const S = [1, 0];
const E = [0, 1];
const N = [-1, 0];
const W = [0, -1];

const SENW = [S, E, N, W];

const BOARD_DIRS = [
    [ [S], [], [S,E], [S,W,E], [S,W] ],
    [ [S,N,E], [S,W,E], SENW, SENW, [S,W,N] ],
    [ [S,N,E], SENW, SENW, SENW, [S,W,N] ],
    [ [S,N,E], SENW, SENW, SENW, [S,W,N] ],
    [ [E,N], [W,N,E], [W,N,E], [W,N,E], [W,N] ] 
];

const BOARD_USED = [
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0]
];

var pathCount = 0;
var maxPathLenReached = 0;
var bestPaths = [];

var findPath = function() {
    var path = [[0, 0]];
    BOARD_USED[0][0] = 1;
    var findRec = function() {
        if (path.length===FULL_PATH_LEN) return true;
        if (path.length>=maxPathLenReached) {
            bestPaths.push(path.slice());
            maxPathLenReached = path.length;
        }
        let pos = path[path.length-1];
        for (let dir of BOARD_DIRS[pos[0]][pos[1]]) {
            let i = pos[0]+dir[0], j = pos[1]+dir[1];
            if (BOARD_USED[i][j]) continue;
            path.push([i, j]);
            BOARD_USED[i][j] = 1;
            if (findRec()) return true;
            path.pop();
            BOARD_USED[i][j] = 0;
        }
        pathCount++;
        return false;
    }
    var wasFound = findRec();
    return wasFound ? path : null;
};

var print = t=> {
	document.body.appendChild(document.createTextNode(t));
  document.body.appendChild(document.createElement("br"));
};

var sol = findPath();
if (sol) {
    print("Found solution: "+sol.join("; "));
} else {
   	print("No solution found");
}

print("Tried "+pathCount+" paths (ending to can't continue)");
print("Max path length: "+maxPathLenReached);
//console.log("All the best paths (incrementally) found: ",bestPaths);
var reallyBestPaths = bestPaths.filter(p=>p.length===maxPathLenReached);
print("Paths found with this length: "+reallyBestPaths.length);