All files / apps/huella-legal/app/plugins navDirection.client.ts

100% Statements 8/8
100% Branches 5/5
100% Functions 4/4
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17652x         42x 70x 70x   70x     42x 582x      
const position = () => (window.history.state as { position?: number } | null)?.position;
 
export default defineNuxtPlugin(({ $router }) => {
    let current: number | undefined;
 
    $router.beforeEach(() => {
        const next = position();
        const back = next !== undefined && current !== undefined && next < current;
 
        document.documentElement.dataset.nav = back ? "back" : "forward";
    });
 
    $router.afterEach(() => {
        current = position();
    });
});