The question: Since the restoration of the LDS church took place in the 1800's, how did one get to heaven before that, when no LDS religion really existed?
The most direct answer can be found in a vision given to the Prophet Joseph Smith in 1836:
Thus came the voice of the Lord unto me, saying: All who have died without a knowledge of this gospel, who would have received it if they had been permitted to tarry, shall be heirs of the celestial kingdom of God;
Also all that shall die henceforth without a knowledge of it, who would have received it with all their hearts, shall be heirs of that kingdom;
For I, the Lord, will judge all men according to their works, according to the desire of their hearts.
The people who died before the Church could be restored still had hope. If they would have accepted the Gospel had they heard it during their lives, they would have been counted among those worthy of Celestial glory. Likewise, today if someone never hears the Gospel before they die, they still have a chance at Heaven. God knows His children perfectly, so this works.
So, a spirit in postmortality can still choose to accept the Gospel. This is why we have temples: to perform the ordinances not only necessary for our own exaltation, but also for the exaltation of the dead. These can only be done with a body (one reason we came to Earth), so we perform proxy baptisms, endowments, and other sacred ordinances for those souls who never had a chance to have them done during their mortal existence. For this reason, and others, the temple is a literal bridge between our world and the Spirit World.
God will never unfairly take away the salvation of His children. He loves all of them, and wants them to return to Him. However, He also will never take away their agency, and sometimes a spirit will choose to reject the Gospel even after physical death. No man will be forced into Heaven. This is important to remember. However, it saddens the Lord when any of His children cannot partake of the fullness of His blessings, because He does love them.
I am grateful to know that the Lord loves us that much, to give His children a way to live with Him again even when they cannot find it in mortality. I'm grateful to have temples and the Gospel on the Earth today. The temple truly is the happiest place in the world, because it is the house of the Lord. It is where His most precious work is done for the immortality and eternal life of His children. Knowing that, it is impossible to deny His infinite love for us. I say these things in the name of Jesus Christ. Amen.