=>I am using one custom page as custom-router in magento2 to redirect between 3 pages "Page1,page2,page3" according to value of $currentPage variable, saved in session.

=>These three pages has two buttons to change the current page and it will change value of $currentPage variable.


if user is on page2 and ofcourse value of $currentPage is page2. And user tries to open page3 in newtab(browser). The custom router is redirecting user to page2.


  1. This routing method is wrong on magento2? If yes then what should be correct approach?
  2. Can we use magento urlrewrite functionality in this case? If yes then how can we check the $currentPage variable value?

  3. It's affecting the page loading time of the pages. How can we avoid that?

  • Why reinvent the wheel ? Magento has a routing system in place. Just use normal pages with links to the others Feb 18, 2018 at 7:53

1 Answer 1

  1. Without knowing too much about the real world use-case I can't tell you if this is the correct approach (should you use this approach or not), just that it can be done.

  2. You probably can't use url rewrite for this.

  3. I imagine because you are using this approach you can't cache the pages with Varnish, hence page loading time issue? If so you can try implementing js redirect: on page load send an ajax to a custom controller to grab the page that the user should be in, the redirect if needed.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.