AltoRouter icon indicating copy to clipboard operation
AltoRouter copied to clipboard

Documentation for setting base path incorrect.

Open elliotboney opened this issue 8 years ago • 4 comments

Just a quick edit to the set base path documentation to save some other people the confusion.

It's documented as

$router->setBasePath('/alto-app/');

and what works is only (without the /):

$router->setBasePath('alto-app');

elliotboney avatar Nov 17 '16 04:11 elliotboney

A bit more details to help out anyone else, and I'll probably submit a pull request later.

The general matcher uses $_SERVER['REQUEST_URI'] which will return a path like:

/foo/bar/?param=value&param2=value2

If you set this value $router->setBasePath('/alto-app/');, you end up with this result.

 /alto-app//foo/bar/?param=value&param2=value2

Note those two forward slashes in the route, which won't match anything.

If you do @elliotboney's route, you get this:

alto-app/foo/bar/?param=value&param2=value2

May or may not be what you want. I set it with $router->setBasePath('/alto-app');

/alto-app/foo/bar/?param=value&param2=value2

NoMan2000 avatar Dec 09 '16 14:12 NoMan2000

I believe setBasePath('/my-base') is the correct way. We could just strip the right / from the path when setting it.

koenpunt avatar Dec 22 '16 22:12 koenpunt

Can confirm, rtrim($base, '/') fixed all my issues.

milankragujevic avatar Apr 08 '18 21:04 milankragujevic

I think with / and without it's same, but work another. How about fix it?

dejurin avatar Sep 09 '18 22:09 dejurin