I found out why it wasn’t working for me - when the Object.assign()
call is made it only modifies the properties and not the entire object so the computed
function is not actually triggered to rerun.
This example works for my use case (hope it helps someone else )
const routerState = Vue.observable<{route: Route}>({
route: {
fullPath: '',
hash: '',
matched: [],
params: {},
path: '',
query: {},
},
});
Router.afterEach((to) => {
Object.assign(routerState, { route: to });
});
export const useRoute = () => computed(() => routerState.route);