Downgrading PostgreSQL 10 to 9.4
Downgrading PostgreSQL is not supported.

You may get lucky and it may work if you have a simple database.
Your way is the best way; test the result as well as you can.