Current active page name in v2

How to get current active page name in v2?

I have a same problem.

var cpage = mainView.activePage;
var cpagename =;

v2 ?

Hi @proteus

You can get current view router path using below code


For parent home page view the output will be

1 Like

Thanks rajkaruna. It is work.

Hi @proteus,

If it satisfies your requirement, please close this question.

@nolimits4web can you explain how to use app.views.main.router.currentPageEl ? i write code console.log(app.views.main.router.currentPageEl) but log always show undefined. please help me, :frowning: anyone know this problem please show me the example code.

thank you before…

I want to use the back button functionality (hardware). If my back button functions put in the index all pages if pressed the back button it will pop up to get out.

I use a code like this. I want this function can only be executed index page only.

document.addEventListener("deviceready", onDeviceReady, false);
	  function onDeviceReady() {
					document.addEventListener("backbutton", onBackKeyDown, false); //Listen to the User clicking on the back button
				function onBackKeyDown() {
					navigator.notification.confirm("Are you sure you want to exit ?", onConfirm, "Confirmation", ["Yes","No"]); 

				function onConfirm(button) {
					if(button==2){//If User selected No, then we just do nothing
						return false;
					}else{;// Otherwise we quit the app.

While the other page, back button executes code router.back();

It may not work in your case if you have dirrent variables names, e.g. you may have myApp instead of app, etc

i dont know how to use that code. after run app.views.main.router.currentPageEl log show all element in index. but i dont know how to initialize Active now that the page index.

i use if (app.views.main.router.currentPageEl == 'home') { //execute command }

but back button not work. my data-name on index page is “home”. sorry i newbie learning in javascript. I am learning javascript in self-taught.

and thank you so much for you answer… god bless you…

if (app.views.main.router.currentRoute.url="/"){
//do some thing
try it

Just wondering if there was an answer to the question of getting the actual “data-name” (used to be “data-page” in v1) specified in the page element?

Page documentation suggests this, but the line fails to execute. - string Value of page’s data-name attribute

I am trying the alternative method in this thread (slight variation) of taking the name from the router information, which I can make work, but I can’t get sensible information for my home page. (url is a long phonegap one, name is undefined). So my code is having to conclude it is on the home page from the fact that there is no history. I am in the process of converting from v1-v4.

In V1 I was using:
var mainView = myApp.addView('.view-main');
var pgn =;

In V4, I wonder why I can’t use:
var mainView = myApp.addView('.view-main');
var pgn =

Using as backup, having specified the name in routes:
var pgn =;

1 Like

It worked for me:

1 Like

Worked for me too. tks!

1 Like

Same, this is working for me: (which gets info from routes)
var mainView = myApp.addView('.view-main');

Was wondering why this doesn’t: (which gets info from “data-name” attribute in the html)