How to redirect on page init?

I need to redirect when my site is loading.
When a user is clicking the “Buy” button in my webshop.asp cart page, I send the info to the payment service and they load my start page with a querystring(paymentId) and then I want to load my webshop.asp cart again to show the “Payment success” info to the user.

I want it to work like this:
When the payment service loads my start page I then check to see if it is loaded with a querystring called paymentId, and if it is then redirect and load the webshop.asp page.

So this is what I have now, but the mainView.router.navigate("/kundvagnen/",{ignoreCache: true}); is not redirecting?

function getUrlParameter(name) {
    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
    var results = regex.exec(location.search);
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};

thepaymentID=getUrlParameter('paymentId');

if(thepaymentID){
	console.log('paymentId has a value '+thepaymentID)
	mainView.router.navigate("/kundvagnen/",{ignoreCache: true});
	
}

So why isn´t mainView.router.navigate("/kundvagnen/",{ignoreCache: true}); redirecting - working?

Thanks a lot.

If you call it inside pageInit then it won’t work, use async route for this purpose instead or route’s beforeEnter

No Im not using it inside pageInit. Ok, Im not sure how it works.

If I have this, should I here check for the querystring? Or? I simply don´t understand how it works :slight_smile:
{
path: ‘kundvagnen’,
url: ‘./shop/kundvagnen.asp’,
beforeEnter: function (routeTo, routeFrom, resolve, reject) {
resolve();
},
},