JSFiddle - React, Tailwind, and code Playground
HTML
<a href="/#/produtos/222">dds</a>
<!-- page of plugin https://github.com/camme/jquery-router-plugin -->
JavaScript
(function($){
var hasPushState = (history && history.pushState);
var hasHashState = !hasPushState && ("onhashchange" in window) && false;
var router = {};
var routeList = [];
var eventAdded = false;
var currentUsedUrl = location.href; //used for ie to hold the current url
var firstRoute = true;
// hold the latest route that was activated
router.currentId = "";
router.currentParameters = {};
router.capabilities = {
hash: hasHashState,
pushState: hasPushState,
timer: !hasHashState && !hasPushState
};
// reset all routes
router.reset = function()
{
var router = {};
var routeList = [];
router.currentId = "";
router.currentParameters = {};
}
router.add = function(route, id, callback)
{
// if we only get a route and a callback, we switch the arguments
if (typeof id == "function")
{
callback = id;
delete id;
}
var isRegExp = typeof route == "object";
if (!isRegExp)
{
// remove the last slash to unifiy all routes
if (route.lastIndexOf("/") == route.length - 1)
{
route = route.substring(0, route.length - 1);
}
// if the routes where created with an absolute url ,we have to remove the absolut part anyway, since we cant change that much
route = route.replace(location.protocol + "//", "").replace(location.hostname, "");
}
var routeItem = {
route: route,
callback: callback,
type: isRegExp ? "regexp" : "string",
id: id
}
routeList.push(routeItem);
// we add the event listener after the first route is added so that we dont need to listen to events in vain
if (!eventAdded)
{
bindStateEvents();
...