A space craft takes the group to various planets. These turn out to be from their imaginations or books they have read, such as Alice in Wonderland. They are pursued by men in black (hats?).
There is a reasonable likelihood that this is Heinlein's The Number of the Beast.
The "spacecraft" is a flying car named "Gay Deceiver", and the people comprise two couples.
They visit Earth on alternate timeline, Mars in the Burroughs timeline (Barsoom), Oz and others. Heinlein's world-as-myth concept is first introduced in this book.
There is an extended subplot concerning who is to be the officer in charge with all four crew taking a turn at it before one of their number of selected by consensus.