Go step by step and test.
1. Restart the router
Startup in Safe Mode and test.
Launch Safari to test.
Restart normally by clicking the “Restart” button at the bottom.
Start up in Safe Mode. https://support.apple.com/en-us/HT201262
2. Delete Caches.db
Back up your Mac.
Close all windows and quit all applications.
Hold "option" key down and click "Go" menu in the Finder menu bar.
Select "Library" from the dropdown.
Library > Caches > com.apple.Safari > Caches.db
Right click the Caches.db file and select "Move To Trash”.
Close windows.
Restart and relaunch Safari.

3. Check for adware.
Use the latest release of Malwarebytes for Mac to remove malware/adware, if installed on your Mac.
For instructions: Install Malwarebytes for Mac Uninstall Malwarebytes for Mac
Click the “Scan Now” button. Once done, quit Malwarebytes for Mac.
Restart the computer and relaunch Safari holding the shift key down.
4 Download EtreCheck, https://etrecheck.com/maspro and post the report here.
Click “Click to download” button,
Open Downloads folder, click on it to open, and then select ”Open”.
“Choose a problem” from the popup menu box, and then “Start EtreCheck” in the dialog.
Click “Share Report” button in the toolbar, select “Copy report” .
Paste the report when you reply.
Note
This is a diagnostic test.
If 5000 words limit applies:
Split the report into two parts and post as two separate posts.