Alter a view that refers to a non-readable secondary database
Can you create a linked server on each AG node that references the AG listener?
You can then alter your view to query DB1 via the linked server using 4-part naming, instead of querying DB1 using 3-part naming. Then you shouldn't encounter this error as the linked server will redirect to the AG primary.