Router.back - not working

myApp.router.back({url: ‘/search/’, force: true, ignoreCache: true, reload: true});

myApp = new Framework7({
swipeBackPage: false,
preloadPreviousPage: false,
})();

Why is it not working? what is the reason?

your code its a little vague to find whats wrong.
but, reading the router doc;

router.back(url, options)

https://framework7.io/docs/view.html#router-api-methods-properties

so, router.back, expects two params or none. if none, the should go back to previos page, if exist. If you call .back( param1, param2) the it should go to the url you pass as the first param.
Your code only send one param to .back.
I think you should somthing like this

myApp.router.back('/search/', {force: true, ignoreCache: true, reload: true})

so now the first param is the url, and the second is an object with your options.

thank you for help…

I edit myApp.router.back(’/search/’, {force: true, ignoreCache: true, reload: true});

then test…cget error: r.currentRoute.route is undefined

can you share the full code where you are calling myApp.router?

    path: '/doc/',
    componentUrl: './pages/doc.php',
    name: 'doc',
    on: {
      pageInit: function (e, page) {
			
			function handle_back(e) {
				
				myApp.router.back('/search/', { ignoreCache: true });
				
			};
			
			$$( '.handle_back' ).click( handle_back('/search/') );
     }
}

I use console.log(e);
Result:

page:afterin
​
bubbles: true
​
cancelBubble: false
​
cancelable: true
​
composed: false
​
currentTarget: null
​
defaultPrevented: false
​
detail: Object { app: {…}, view: {…}, router: {…}, … }
​
eventPhase: 0
​
explicitOriginalTarget: <div class="page no-navbar page-current" data-page="doc">

ok, can you do

console.log(JSON.stringify(page,null, 2))

and post the result.

TypeError: cyclic object value[Learn More]
routes.js:535:16
pageInit
http://localhost/ts-new/ts-android/assets/custom/js/routes.js:535:16
pageInit self-hosted:977:17 l
framework7.js:1068:4
trigger
framework7.js:1168:15
Router</t.prototype.pageCallback
framework7.js:8322:4
forward
framework7.js:6041:2
m
framework7.js:6198:11
Router</t.prototype.pageComponentLoader/<
framework7.js:8163:6
s
framework7.js:8125:6
Router</t.prototype.componentLoader/

"$el": Object [ div.page.no-navbar.page-current ]
​
"$navbarEl": Object { length: 0 }
​
"$pageEl": Object [ div.page.no-navbar.page-current ]
​
app: Object { id: "com.myapp.test", name: "Framework7", version: "1.0.0", … }
​
direction: "forward"
​
el: <div class="page no-navbar page-current" data-page="doc">
​
from: "next"
​
name: null
​
navbarEl: undefined
​
pageEl: <div class="page no-navbar page-current" data-page="doc">
​
pageFrom: Object { app: {…}, view: {…}, router: {…}, … }
​
position: "next"
​
route: Object { url: "/doc/", … }
​
router: Object { params: {…}, eventsParents: (1) […], isAppRouter: false, … }
to: "current"
​
view: Object { params: {…}, eventsParents: (1) […], main: true, … }
​
__proto__: Object { … }

you should have acces to router in page

page.router.back(param1, param2)
or
page.app.router.back(param1, param2)

i tried both of them… it still not working :frowning:

so, thats not helping, what error does you see in the console?
can you make a jsfiddle?
you are using f7-v2, right?

I can’t make a jsfiddle/ yes I using V2
I looking on console and is it help what I found.

router: {…}
​​
“$el”: Object [ div.view.view-main.view-init.ios-edges ]
​​
“$navbarEl”: undefined
​​
allowPageChange: true
​​
app: Object { id: “com.myapp.test”, name: “Framework7”, version: “1.0.0”, … }
​​
back: function back()
​​
backward: function backward()
​​
cache: Object { xhr: (4) […], templates: [], components: [] }
​​
clearPreviousHistory: function clearPreviousHistory()
​​
currentPageEl:


​​
currentRoute: Getter & Setter
​​
dynamicNavbar: false

any suggest you can help please?

Ok, so im just guessing. you dont provide much info.
change

myApp.router.back

for

e.router.back
1 Like

router methods must be called on view instance, so it must be page.router.back inside of page handler.
Also you have error in JS:

$$( '.handle_back' ).click( handle_back('/search/') );

must be

$$( '.handle_back' ).click(function () {
  handle_back('/search/');
});

There is a huge difference between these two.

If it won’t help, then JSFiddle will be appreciated

2 Likes

Appreciate for all your help. Thanks.

Final result for everyone to use it :slight_smile:

function handle_back(e) {
myApp.router.back( e , {ignoreCache: true, reload: true} );
}

$$( ‘.handle_back’ ).click(function () {
handle_back(’/search/’);
});