[Cleanup] navigate.js
[Cleanup] Factorise some duplicate code in navigate.js