Mangling back button functionality isn't inherent of SPAs.
It is super common to see "Don't use your back button" messages after placing orders on e-commerce websites.
On the other hand, most frontend developers writing SPAs just use react-router or something like that (instead of reinventing the wheel) and it just works.
Yet there was a post about how specifically to do that on dev.to because their users couldn't tell their modal was a modal, and the solution they came up with was to hijack the back button.