How do I handle multile trailing slashes for optional routes?

Hi There,
I am having trouble in multiple optional routes trailing slashes
For example
category/sub-category/category

if making the optional route slash for the end of the URL it’s working
Ex: category/sub-category/category/ This is working as
but for other ones it’s not working
Ex: category/sub-category/
Ex: category/

How do I handle for the other routes?

Look at this:

Unable to access page unless I enter trailing slash