Can't evaluate field URL in type *hugolib.pageState

I’m using an older theme and get an error with this line now.
How can I fix it?

{{ $url := .URL }}

I changed it to this now:

{{ $url := .Permalink }}

Is it a good idea?

Isn’t that URL depreciated and not longer user in Hugo? Warning been back in 2021 in it.

Try replacing with .RelPermalink

If it works, yes. .Permalink or .RelPermalink is used nowadays.