Yii 2 – Fix weird page navigation with # (hash) symbol as you go to a new page

By | October 12, 2014

I ran into an issue with Yii 2 where I would click a link, it would go to that link but at the same time on the URL a little # symbol would appear then dissapear. It looks like this causes no issues until you try to navigate back. When you hit back, the page wouldn’t load but the URL would go back. Refreshing would fix it but that still isn’t good.

I figured out that this happened when using Pjax. Make sure that any links in a Pjax block have the data-pjax=”0″ parameter. So the URL would need to be like:

<a href=”/site/home” data-pjax=”0″>Home</a>

This is actually documented in the Yii 2.0 manual so if you are looking for more information you can check there.

Leave a Reply

Your email address will not be published. Required fields are marked *