/JsRouting

📍 A simple JavaScript routing system for web applications that leverages Apache .htaccess rules for handling single-page application (SPA) routes.

Primary LanguageJavaScript

JsRouting 📍💻

About

JsRouting is a simple JavaScript routing system with one slash route /.

Compatibility

  • https://example.com/example
  • https://example.com/:username
  • https://example.com/home/example
  • https://example.com/home/example/example/...

CDN :

https://cdn.jsdelivr.net/gh/im95u/JsRouting/index.js

Documentation 📜

1️⃣ First setup your server Apache .htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

Nginx

location / {
  try_files $uri $uri/ /index.html;
}

2️⃣ Second Start Using JsRoute

🔴 Please make sure you use this code after the page has loaded successfully 🔴

✨ Simple Route

var jsRoute = new JsRoute();

jsRoute.get("/example", function() {
  alert("Wow! 😁");
});

🎉 Parameter Route

var jsRoute = new JsRoute();

jsRoute.get("/:username", function(username) {
  alert("Wow! 😁\nUsername : " + username);
});

📛 Some Errors

jsRoute.get("/example/two") 
jsRoute.get("/example/:parameter") 

🤔 If you have a problem, contact me via:

Issues section: https://github.com/im95u/JsRouting/issues

Discord: upsilun#6775