Make routing decision based on data of Vue instance

vue-router

#1

In a beforeEach navigation guard, I want to make a decision based on whether someone is currently logged in.

This works when the application is already loaded, but not for the first page load, because router.app is not initialized yet.

Repro:
https://jsfiddle.net/q574co12/

Expected:
Browser shows “Hello”
Console output: “Joe”

Actual:
Browser shows “Please log in”
Console output: undefined

In the repro example I hardcoded the user name, but normally I would populate the root instance’s data from a window variable.

This doesn’t seem to work anymore.