In my view nationalism was the main cause of WWI because nationalism was the driving force behind many of the event which escalated tensions in Europe in the early 20th century. Firstly, German nationalism lead to the Anglo-German naval race as German nationalists felt that challenging Britain's naval hegemony would increase German prestige and lead the way for greater German Imperial possessions in Africa. In this way, nationalism was closely connnected to imperialism as overseas colonies were seen as a way to increase national glory and prestige by many. Britain was very anxious about Germany's intense naval build-up in the early 20th century as the British government felt thats its imperial strength was predicated on its naval supermacy. This unsurprisingly lead to greater tension and hostility between the two nations. Secondly, in 1908 Austrian and Serbian nationalism clashed over the possession of Bosnia. This lead to increased tension in the Balkan region which is where the events directly leading to WWI would eventually take place. Serbian nationalists saw this as a chance to create a 'greater Serbia' which would include Bosnia whereas Austrian nationalists saw possession of Bosnia as a natural extention of their power into the Balkan region. The issue divided the great European powers with Germany backing the Austrians and Russia and Britain backing the Serbians. This regional issue managed to increased hostility accross the whole continent which drove Europe one step closer to war. Finally, In 1911, in response to French imperial expansion into Morrocco, Germany sent a gunboat to Agadir in an attempt to intimidate the French. German nationalists believed that Germany deserved possessions in Africa equal to the British and the French as it was an industrialised great European power. Eventually the Germans backed down due to the threat of war and was compensated with a small piece of undesireable land in the Congo. This was massively humiliating to many German nationalists and lead to very poor relations between the evetual primary belligerents of the first world war. Competing nationalisms accross Europe clearly increased tension and hostility paving the way for eventual total war.
However, there were also other important causes to WWI. The system of alliances was an important cause as two power blocs gradually developed in Europe with Britain, France and Russia on one side and Germany, Austria, and the Ottomans on the other. This made war more probably as the major powers felt stronger as they had allies which they felt they could rely upon. For example after the German unconditional support of Austria is argued by some historians to be a reason why Austria acted aggressively and stubbornly in diplomacy with the Serbians. Additionally, the most immediate cause of WWI was the assassination of Austrian Archduke Franz Ferdinand in July 1914 leading to a major diplomatic crisis between Austria and Serbia. It was this event which lead to the first formal declarations of war and as such is a very important cause of the first World War.