Route parameters separator questions

Thank you @Teodor.

If I may ask a quick question, I’m trying to create this url string with routing:

example.com/level1/firstname-lastname_id

In routing it looks like this:
example.com/level1/:firstname-:lastname_:id

But it appears the underscore is playing a different role and is being included in the :lastname parameter, instead of being a seperator. Can you advise how I should correctly route the above path?

It’s also strangely (with the above string) cutting off the first letter of the :firstname parameter when I look at the response in the network tab.

I can get it working with hyphen’s but not the underscore

The name of route parameters is made up of “word characters” ([A-Za-z0-9_]). The route example.com/level1/:firstname-:lastname_:id will result in the parameters firstname, lastname_ and id. You see that the _ will be part of the parameter. To separate parameters in a path use /, - or ..

1 Like

Thanks Patrick, is there any way to include an underscore that does not consider itself part of the parameter?

The reason why I’d like to use underscore is we are migrating an existing, live site and all the url paths have an underscore, the minute we remove them, we’ll lose have dead links and take a big hit in traffic.

Did some testing, try the following as path:

example.com/level1/:firstname-:lastname[_]:id

Unfortunately didn’t work - page doesn’t pick up the data - if I type [] in the actual browser url path it works, but if I use this in the routing and then just have :lastname:id it doesn’t work or pick up data :frowning:

Do you use NodeJS, PHP or ASP?

NodeJS

Then adding a route path with /level1/:firstname-:lastname[_]:id should work, using a browser url like example.com/level1/patrick-woldberg_1 it should return the params firstname=patrick, lastname=woldberg and id=1.

hmm, let me try again and come back to you

Hey @patrick got back to this today.

I created the route path as you suggested or e.g. (/recruiters/:firstname-:lastname[_]:id), and then created a dynamic link on the page. When I click save the path changes to this:

Screen Shot 2020-08-27 at 3.10.09 pm

And this transfers to the URL when rendered and clicked:

Screen Shot 2020-08-27 at 3.12.36 pm

Which is naturally not the desired result. Can you please advise?

You should not include the [] (%5B and %5D) in the url, the brackets are only needed in setting the path for the route since it treads it as a regex.

I’m not adding it - Wappler is generating it when I try to create the path in the UI. I’ve only added [] in the route path

Just remove the [] from the URL.
So your dynamic url should look like:

dmx-bind:href="'/recruiters/' + firstname + '-' + 
lastname + '_' + id"

Thanks Teo, but unfortunately it then doesn’t work on the actual page (pulling in the data).

Route on the page:

Route setup in the routes panel:
Screen Shot 2020-08-28 at 8.13.42 am
and
Screen Shot 2020-08-28 at 8.14.01 am

dynamic url manually changed as suggested:

Screen Shot 2020-08-28 at 8.14.35 am

page URL

query param on page:
Screen Shot 2020-08-28 at 8.16.03 am

input on server connect.
Screen Shot 2020-08-28 at 8.17.28 am

When ( %5B and %5D ) exists on the URL - it works, and the page renders with data. When it’s removed, it doesn’t render at all.

I see, maybe @patrick can advise here.

1 Like

Yes please Patrick! :slight_smile:

The problem is with the _, if you change that to a - or / then it would have no problems with the path. I will do some testing to see if the _ will give me the same problems.