Router.back - not working


#1

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?


#2

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.


#3

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


#4

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


#5
    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">

#6

ok, can you do

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

and post the result.


#7

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/


#8
"$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 { … }

#9

you should have acces to router in page

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

#10

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


#11

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


#12

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

#13

any suggest you can help please?


#14

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

myApp.router.back

for

e.router.back

#15

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


#16

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/’);
});