[SOLVED] beforeLeave: Could not go back to the page

Hi, as explained in the documentation (Routes | Framework7 Documentation),
before the user leaves the page by clicking on the “back” button I would like to ask for confirmation through a dialog. If the user clicks on “Confirm”, the app must go back to the page, if he clicks on “Cancel” no.
This is my code. I can’t get the page back after pressing the “confirm” button.
Where am I doing wrong?

     `  routes: [
				name: 'company-add',
				path: 'add/',
				url: './pages/company/add.html',
				on: {
						pageInit: function(e,page){ 
								//some code
						pageAfterIn: function(e,page){ 
							//some code
				    beforeLeave: function ({ resolve, reject }) {
						'Are you sure you want to leave this page without saving data?','Confirm',
						function () {
							// go back
						function () {
							// stay on page

Thank you in advance, for your support.

from docs => competent-ramanujan-td3z2r - CodeSandbox

1 Like

Thank you @deejay. However in my project, using your code, I received the following two errors:

  • Uncaught TypeError: resolve is not a function
  • Uncaught TypeError: reject is not a function

Maybe I forgot to activate some settings?

I solved writing the same function with the following parameters:

beforeLeave: function (routeTo, routeFrom, resolve, reject){
					  "you want to leave this page?",
					  () => resolve(),
					  () => reject()

Thank you so much.

using v5 you should refer to v5 docs => Routes | Framework7 Documentation