-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid link with persistent parameter #43
Comments
Thanks for reporting. Can you please add example code how to induce this bug? |
Adding clean nette web project with implemented navigation with showing generated link and plink in template (they are ok) and menu (not ok) Try to change language string in url and you see that links are changes but language in menu keep using default from router, not actual value of the variable. Tested on PHP7.4 |
I trying to write my own menu component and I end at the same problem when I trying to generate url myself (not using latte). It seems like problem is LinkGenerator in nette. It ignores parameters defined in route and use defaults instead. |
Yes, this will be probably the cause, because Solution would be create your own implementation of |
Yes. Nette LinkGenerator is wrong. I wandering that maybe will be possible to use RouteList and Request to make own LinkGenerator but I don't know how to access parameters from router :( |
For somebody, who stumble upon this as I did, here is a hacky workaround: use Carrooi\Menu\IMenuItem;
use Carrooi\Menu\LinkGenerator\ILinkGenerator;
use Nette\Application\Application;
use Nette\Application\UI\Presenter;
final class NetteLinkGenerator implements ILinkGenerator
{
private Presenter $presenter;
public function __construct(Application $application)
{
$this->presenter = $application->getPresenter();
}
public function link(IMenuItem $item): string
{
if(($action = $item->getAction()) !== null) {
return $this->presenter->link($action, $item->getActionParameters());
}
if (($link = $item->getLink()) !== null) {
return $link;
}
return '#';
}
} The caveat is that now it recognizes relative vs absolute links, so in your config file, all your links now have to start with a colon. I can give you no warranty, I just tried this out and persistent parameters works, but I have no idea if something else isn't broken. |
Since this is not |
@foxycode I guess this really depends on the point of view. Since it is a presented as Nette component, but it does not work fully with Nette. It should be at least mentioned somewhere in the documentation, WDYT? |
@patrickkusebauch You're right. Will think about it. |
Found a bug.
Trying to use route with language parameter which is persistent parameter in presenter.
All links generated in project are okay but links in menu-control don't respect actual value of the parameter. Instead there are just default parameter value for route.
The text was updated successfully, but these errors were encountered: