[RESOLVED] Prevent button click or page display, based on a condition

Hi,
Am trying to prevent access to a page(moderators page) on clicking a link. The thing is, that page is allowed for only Moderators. So I don’t want other normal users to access it.

Am having a boolean attribute inside: app.data.user.is_moderator

So, am trying to use this boolean value to restrict access to the page.
Tried the following way, but it doesn’t seem to be blocking it:

$$('.only_moderator').on('click', function(){
  return false;
});

And this is the element:

<a href="/admin/" class="item-link list-button panel-close only_moderator">Admin Panel</a>

Any suggestions?

1 Like

Hi dev,

One small suggestion, you are using a router in (href = ‘/ router_path /’)

Change

href = '#'

Change your logic a bit …

Try it …

function function_login () {

// apply your conditions
// if true, redirect to

app.router.navigate ('/ admin /', {clearPreviousHistory:true})

}

$$ ('. only_moderator'). on ('click', function () {
   function_login ();
});
1 Like

Awesome!

Though, I found that setting clearPreviousHistory to true was not needed!

1 Like

Hi Dev,:wink:
Then you already understood how to pass the options.

PS. Minor correction in previous post {clearPreviousHistory:true}

There are other, useful parameters see in the documentation.
http://framework7.io/docs/view.html#router-api-methods-properties

I gave this example because if you hit the back button on Android, it retrieves not the previous page

/admin/

1 Like