It is simply not the case that a preposition always comes before a noun or pronoun. It often does, but sometimes it doesn’t. It is easy to find examples (particularly from everyday speech) that illustrate the point: I don’t know which train I’m on, Paddington is the next station we’ll arrive at, and so on. You could of course say I don’t know on which train I am – but it would be hard to find any native speaker of English who would say that; you could say Paddington is the next station at which we will arrive – but very few people these days would use such a formal construction in ordinary speech.
There is, in fact, an old argument surrounding the point: whether it is (so-called) ‘better English’ to keep the preposition next to the noun or pronoun, or whether attempts to do so sometimes lead to ludicrous results that prove the ‘rule’ to be a silly myth. The most famous example is probably: This is the sort of nonsense up with which I will not put. Obviously, anyone who isn’t a prize idiot would say This is the sort of thing I won’t put up with – using the preposition at the end of the sentence.