noun, adverb
on the way back; while returning
Describes an action or event that occurs during the return journey. Often used adverbially with に.
帰りがけにコンビニに寄った。
I stopped by the convenience store on the way back.
noun, adverb
when about to go back; just before leaving
Refers to the moment just before departing to return. Often used in set phrases like 帰りがけに一言.
I said 'thank you' just before leaving.