In this paper we prove several results regarding decidability of the membership problem for certain submonoids in amalgamated free products and HNN extensions of groups. These general results are then applied to solve the prefix membership problem for a number of classes of one-relator groups which are low in the Magnus-Moldavanskiȋ hierarchy. Since the prefix membership problem for one-relator groups is intimately related to the word problem for one-relator special inverse monoids in the E-unitary case (as discovered in 2001 by Ivanov, Margolis and Meakin), these results yield solutions of the word problem for several new classes of one-relator special inverse monoids. In establishing these results, we introduce a new theory of conservative factorisations of words which provides a link between the prefix membership problem of a one-relator group and the group of units of the corresponding one-relator special inverse monoid. Finally, we exhibit the first example of a one-relator group, defined by a reduced relator word, that has an undecidable prefix membership problem.