Joshua1:8

לֹא־יָמוּשׁ סֵפֶר הַתּוֹרָה הַזֶּה מִפִּיךָ וְהָגִיתָ בּוֹ יוֹמָם וָלַיְלָה לְמַעַן תִּשְׁמֹר לַעֲשׂוֹת כְּכָל־הַכָּתוּב בּוֹ כִּי־אָז תַּצְלִיחַ אֶת־דְּרָכֶךָ וְאָז תַּשְׂכִּיל׃

This book of the Torah shall not depart from your mouth, and you shall meditate on it day and night, so that you may keep and do all that is written in it, for then you will make your way prosper, and then you will act wisely.

Joshua 1:8

לֹא־יָמוּשׁ סֵפֶר הַתּוֹרָה

Yehoshua / Joshua 1:8 · Drash

Joshua 1:8

לֹא־יָמוּשׁ סֵפֶר הַתּוֹרָה הַזֶּה מִפִּיךָ וְהָגִיתָ בּוֹ יוֹמָם וָלַיְלָה לְמַעַן תִּשְׁמֹר לַעֲשׂוֹת כְּכָל־הַכָּתוּב בּוֹ כִּי־אָז תַּצְלִיחַ אֶת־דְּרָכֶךָ וְאָז תַּשְׂכִּיל׃

This book of the Torah shall not depart from your mouth, and you shall meditate on it day and night, so that you may keep and do all that is written in it, for then you will make your way prosper, and then you will act wisely.

Drash דְּרָשׁ

Success here, wisdom there

The verse says "then" twice. The midrash sees in this two worlds in which the Torah leads a person.

Midrash Tehillim: the righteous one is like a tree transplanted so firmly that no winds in the world will move it from its place. If the Torah does not depart from your mouth, "then you will make your way prosper" in this world, "and then you will act wisely" in the world to come. So Shlomo (Solomon) said: on the way it leads you, in the grave it guards you, and on waking it speaks for you.

How Midrash Tehillim explain it

Midrash Tehillim Like a tree transplanted

Another interpretation: "like a tree transplanted". It does not say "planted" but "transplanted". This teaches you: even if all the winds in the world blow on it, they do not move it from its place. "This book of the Torah shall not depart from your mouth" (Yehoshua / Joshua 1:8). If you have done so, "then you will make your way prosper" (there) in this world, "and then you will act wisely" in the world to come.

Shlomo said: "When you walk, it will lead you" (Mishlei / Proverbs 6:22), in this world. "When you lie down, it will guard you" (there), in the grave, from the worm. "And when you awake, it will speak with you" (there), in the world to come.

Takeaway

The midrash reads the two "then"s of our verse as two worlds: the first is this world, the second the world to come.
"Like a tree transplanted by streams of water": so Tehillim (Psalms) 1:3 speaks of the person who meditates on the Torah day and night (Tehillim / Psalms 1:2).