This passage is Joshua giving his final words to the children of Israel before he died.
Jos 23:6-8 Be ye therefore very courageous to keep and to do all that is written in the book of the law of Moses, that ye turn not aside therefrom to the right hand or to the left; That ye come not among these nations, these that remain among you; neither make mention of the name of their gods, nor cause to swear by them, neither serve them, nor bow yourselves unto them: But cleave unto the LORD your God, as ye have done unto this day.
Joshua encourages the children of Israel to be courageous in keeping and doing all that was written in the book of the law. He encouraged them to not turn to the left or the right, he told them that they should not mention the false gods of the other nations, take an oath by them, serve the false gods or bow down to them. Joshua was very aware that the children of Israel frequently struggled with the sin of idol worship. Instead of just telling them what not to do, he also told them what they should do. He told them to cleave to the Lord!
Jos 23:9-11 For the LORD hath driven out from before you great nations and strong: but as for you, no man hath been able to stand before you unto this day. One man of you shall chase a thousand: for the LORD your God, he it is that fighteth for you, as he hath promised you. Take good heed therefore unto yourselves, that ye love the LORD your God.
Joshua then gives the people a reason to cleave to the Lord. It wasn't just because "I said so;" it was because the Lord had given the people great victories, and in the future He would give them great victories because the Lord was fighting them. Then Joshua tells the people to take heed unto themselves to love the Lord.
Jos 23:12-13 Else if ye do in any wise go back, and cleave unto the remnant of these nations, even these that remain among you, and shall make marriages with them, and go in unto them, and they to you: Know for a certainty that the LORD your God will no more drive out any of these nations from before you; but they shall be snares and traps unto you, and scourges in your sides, and thorns in your eyes, until ye perish from off this good land which the LORD your God hath given you.
Joshua tells the people what would happen if they did not cleave to and love the Lord. If they did not obey the Lord, the Lord would not drive the nations out of the land. Instead those nations would cause many problems for the children of Israel.
Jos 23:14-16 And, behold, this day I am going the way of all the earth: and ye know in all your hearts and in all your souls, that not one thing hath failed of all the good things which the LORD your God spake concerning you; all are come to pass unto you, and not one thing hath failed thereof. Therefore it shall come to pass, that as all good things are come upon you, which the LORD your God promised you; so shall the LORD bring upon you all evil things, until he have destroyed you from off this good land which the LORD your God hath given you. When ye have transgressed the covenant of the LORD your God, which he commanded you, and have gone and served other gods, and bowed yourselves to them; then shall the anger of the LORD be kindled against you, and ye shall perish quickly from off the good land which he hath given unto you.
Joshua tells the people that he is dying! He reminds the people how the Lord had kept word. If the Lord kept His word about the good things, then the Lord would keep His word about the bad things. If the children of Israel did not obey the Lord then they would receive the consequences.
This story as many truths we can apply to our lives, then teach to our children. Joshua told the people to keep and do the Lords commands, to cleave to the Lord and to love the Lord. If we do those things we will not be cleaving to the things of the world. Joshua, as he was instructing the people gave them reasons for cleaving and loving. The reasons were because the Lord keep His word, and would continue to keep His word. Are we teaching this lesson to our children? Do our children see us loving and cleaving to the Lord? To we given them reasons why we do those things or is it "because I said so"? Our relationship with the Lord is so important because our children can tell if we are giving lip service to the Lord, or if we really have a relationship with the Lord.
When I was younger, occasionally I would go over to my grandparents house to spend the night. One of the things that I remember is devotions with my grandparents. They would read a short devotional, some Scripture and then pray. As I listened to my grandfather pray, I knew that he had a special relationship with the Lord. That is the kind of relationship I want with the Lord!