Redirection on init is not working?


#1

Below redirection is not working and getting app is undefined error

{
		path: '/',
		url: './index.html',
		name: 'home',
		on: {
			pageBeforeIn: function (event, page) {
				console.log('beforein');
			},
			pageAfterIn: function (event, page) {
				console.log('Afterin');
				// do something after page gets into the view
			},
			pageInit: function (event, page) {
				// do something when page initialized
				var self = this;	               
				//var app = self.$app;
				self.app.router.navigate('/xyz/');
			},
			pageBeforeRemove: function (event, page) {
				console.log('before remove');
				// do something before page gets removed from DOM
			},
		}

	}

#2

It is not a component but rather page event, check page data object docs http://framework7.io/docs/page.html#page-data

it will should be

var app = page.app

#3

Thanks for your quick reply. However is not working.

    {
		path: '/',
		url: './index.html',
		name: 'home',
		on: {
			pageBeforeIn: function (event, page) {
				console.log('beforein');
			},
			pageAfterIn: function (event, page) {
				console.log('Afterin');
				// do something after page gets into the view
			},
			pageInit: function (event, page) {
				// do something when page initialized
				//console.log(page);
				console.log('init 123');
				var app = page.app
				app.router.navigate('/newsfeed/');
				console.log('am herer');
			},
			pageBeforeRemove: function (event, page) {
				console.log('before remove');
				// do something before page gets removed from DOM
			},
		}

	}

#4

Ok, just realized that you are doing redirect. Redirect will not work within page init. What is the point to load the page and redirect to another one immediately. Use async routes for that or route redirects


#5
Thanks for your quick reply. before showing dashboard i need to check user has logged in or not. 

so am using empty index.html with left side navigation once index.html loaded on init am checking user have logged in session or not, based on that am redirecting to login or dashboard page. For this scenario i need redirection on index init method.

#6

For this scenario use async route http://framework7.io/docs/routes.html#async-route


#7

Could you please explain much more details, i have used asyn on index however this method is not calling for index route alone. Please provide how i can handle router for this scenarios.\

1 with out login redirect to login page

  1. with login redirect to dashboard page.

#8

http://framework7.io/docs/view.html#initial-page-route


#9

thanks. Here i need to use asyn method for session checking right?


#10

i tired no luck. could you please share any working sample for this scenario its helps for more people because every site they might follow this logic..


#11

Please show what you have tried


#12

Learnt async from downloading a template and seeing how it was used… It is way too powerfuol than you can actually imagine… With a template example, what you read in the docs makes more sense…