Rashi on Joshua
1:1א׳:א׳
1 א

וַיְהִי אַחֲרֵי מוֹת משֶׁה מְחוּבָּר עַל סֵדֶר הַתּוֹרָה הַמְסַיֶּימֶת בִּפְטִירַת משֶׁה, וְזֶה מְחוּבָּר לָהּ.

And after the death of Moshe. This is connected to the chapter of the Torah1The spirit of prophecy did not rest upon Yehoshua until the thirty day mourning period for Moshe was over. It was then that God began to speak to him and command him to begin the conquest of Eretz Yisroel. Yehoshua was in a state of sadness and the spirit of propecy does not rest upon a person who is sad. There are other Seforim in Tanach such as Ruth, Esther, Yonah that begin with the word וַיְהִי, and it was, that are not connected to any previous event. But here the beginning is definitely connected with the conclusion of Sefer Devorim where the death of Moshe is related. which concluded with the passing of Moshe;2Devorim 34:5,6,7,8. and this (Seifer Yehoshua) is connected to it.3Devorim 34:9.