0

I have the following URL https://mywebsite/somepage/1234/5678 where somepage is a route to a page and the numbers are are parameters.

My page is a static page, just html and javascript. Ex.: https://mywebsite/somepage.html.

How could I open this page given the above url get the parameters inside the page?

The reason for this is that I have a mobile deeplink direct the user to a website so that it can download the app in case it isn't installed or to the app itself. I don't have the choice to use a dinamic page with a routing system like in Cake PHP or in Spring Framework.

Natanael
  • 1,326
  • 5
  • 17
  • 34

2 Answers2

0

If you want to load the normal page (https://mywebsite/somepage.html) then you could use hashes instead. They don't get seen by the server, so it would serve the regular html file.

// get the url
var url = window.location.href; // = "https://mywebsite/somepage.html#1234/5678"

// get the bit you want
var params = url.substring(32); // = "1234/5678"
//            ^ the length of "https://mywebsite/somepage.html#"

// split it apart into individual parts
params = params.split("/"); // = ["1234", "5678"]

// then do whatever you like with the params
Whothehellisthat
  • 2,072
  • 1
  • 14
  • 14
0

Create array from current pathname split on /

var urlPath = window.location.pathname.split('/');

Do something with the array...

urlPath.forEach(function(item) {
    console.log(item);
});
Kenneth Stoddard
  • 1,409
  • 11
  • 13