がけにon the way; just as leaving
がけ goes on a few verbs of going and coming to say "on the way" or "just as I was leaving": 帰りがけに, 行きがけに, 出がけに. They are fixed words, and people don't make new ones.
On my way home I stopped at the bookshop by the station and bought a new release.
A delivery came just as I was leaving, and I missed my train.
How to form it
Verb ます-stem + がけに (a few verbs only)
Mostly 帰りがけに, 行きがけに, 出がけに and 通りがけに. Before a noun it is がけの: 出がけの電話, a call just as you were leaving.
The words
帰りがけにon the way home; on your way out
Please return the key to reception on your way out.
行きがけにon the way there
I bought some water at a convenience store on the way there.
出がけにjust as you are leaving
Just as I was leaving, I realized I didn't have my wallet.
通りがけにin passing
As he passed, he looked up at the shop's sign.
通りがかりにhappening to pass by
I happened to be passing and found a new bakery.
A relative, with がかり. 通りがかりの人 is a passer-by.
帰りがけに and 行きがけに can be anywhere along the way. 出がけに is the doorstep: you were just going out.
来がけに, on the way here, is said too, though less. There is no 食べがけに or 読みがけに. And 命がけ (at the risk of your life) and 三人がけ (seating three) are different words.
The plain way to say it
I stopped at the supermarket on my way home.
The fixed word.
I stopped at the supermarket on my way home.
The same, in the plainest words.
Both are everyday. The plain 帰りに, 行きに and 出かけるときに are heard more.
Close neighbours
途中でN2
The open one: any trip, and anything else with an end to reach, such as a meeting or a book.
The train stopped while I was on my way home.
かけ・かけるN3
Without the voicing, and on many verbs: started and not finished.
I put my half-read book on the desk.
ついでにN3
"While I'm at it", for any errand you fit in, not only on the way somewhere.
Could you pick up the dry cleaning while you're out shopping?
Check yourself
1Which one can be said?
Choose an answer to see why.
2What does this say?
出がけに
Choose an answer to see why.
More sentences
I handed the papers for tomorrow's meeting to a colleague who was on his way out.
A phone call just as we were leaving changed our plans.