Home > Software engineering >  has any way let php to detect front-end routing changes?(angular)
has any way let php to detect front-end routing changes?(angular)

Time:08-06

I have an angular form embedded in a php page. When the angular form is sent out, it will navigate to some page.

In practice, when angular form after completing, will use: router.navigate or router.navigateByUrl to a specific route. And those routes have exactly the same page in php.

Example:

in angular

...
this.router.navigate([done], { queryParams: { anyKey: 'anyValue' }});
...

in php

...
done.php

<?php
echo('I got it');
?>

But in reality we know that done.php will never say "I got it" because done.php has never been executed at all.

The problem is that php does not detect the front-end routing was change happen. I understand that this makes sense, but has any way to let php know that the front-end routing has changed?

thank any help.

CodePudding user response:

when you are using a frontend framework like react, angular, vue and so on the frontend and backend should only communicate with each others through APIs so if you want php to collect the form data that you just submitted then you should send these data to php through an API and after receiving the response from php then you can route the user to the done route

but without APIs the php will never know what’s happening on the user side because it's all handled through JS

CodePudding user response:

Yes, eventually I came up with a very old solution.

window.location.href= 'some where' ;

This solved my problem because my boss wanted the gtag conversion rate tracking code to 'must' run in php and he didn't trust angular to run it, so I had to find a way around it.

I would welcome any answers, even though it has been solved using ancient methods.

  • Related