Home / File/ router.ts — astro Source File

router.ts — astro Source File

Architecture documentation for router.ts, a typescript file in the astro codebase. 4 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 4 imports 16 functions

Entity Profile

Dependency Diagram

graph LR
  2b5c33e2_176e_e839_f05f_7f10493f4f74["router.ts"]
  0d5629a5_6f4f_7084_1a43_86f522f2d2e4["../../transitions/events.js"]
  2b5c33e2_176e_e839_f05f_7f10493f4f74 --> 0d5629a5_6f4f_7084_1a43_86f522f2d2e4
  4d9d07b9_627f_6a05_3aae_2cf1418e53a8["./swap-functions.js"]
  2b5c33e2_176e_e839_f05f_7f10493f4f74 --> 4d9d07b9_627f_6a05_3aae_2cf1418e53a8
  af0fc1f4_1b53_7159_e40a_c13f7f62570b["./types.js"]
  2b5c33e2_176e_e839_f05f_7f10493f4f74 --> af0fc1f4_1b53_7159_e40a_c13f7f62570b
  e71ad64b_c09a_453c_08ca_769c94c725b5["client"]
  2b5c33e2_176e_e839_f05f_7f10493f4f74 --> e71ad64b_c09a_453c_08ca_769c94c725b5
  style 2b5c33e2_176e_e839_f05f_7f10493f4f74 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { internalFetchHeaders } from 'virtual:astro:adapter-config/client';
import type { TransitionBeforePreparationEvent } from './events.js';
import {
	doPreparation,
	doSwap,
	TRANSITION_AFTER_SWAP,
	onPageLoad,
	triggerEvent,
	updateScrollPosition,
} from './events.js';
import { detectScriptExecuted } from './swap-functions.js';
import type { Direction, Fallback, Options } from './types.js';

type State = {
	index: number;
	scrollX: number;
	scrollY: number;
};
type Navigation = { controller: AbortController };
type Transition = {
	// The view transitions object (API and simulation)
	viewTransition?: ViewTransition;
	// Simulation: Whether transition was skipped
	transitionSkipped: boolean;
	// Simulation: The resolve function of the finished promise
	viewTransitionFinished?: () => void;
};

const inBrowser = import.meta.env.SSR === false;

export const supportsViewTransitions = inBrowser && !!document.startViewTransition;

export const transitionEnabledOnThisPage = () =>
	inBrowser && !!document.querySelector('[name="astro-view-transitions-enabled"]');

const samePage = (thisLocation: URL, otherLocation: URL) =>
	thisLocation.pathname === otherLocation.pathname && thisLocation.search === otherLocation.search;

// The previous navigation that might still be in processing
let mostRecentNavigation: Navigation | undefined;
// The previous transition that might still be in processing
let mostRecentTransition: Transition | undefined;
// When we traverse the history, the window.location is already set to the new location.
// This variable tells us where we came from
let originalLocation: URL;

const announce = () => {
	let div = document.createElement('div');
	div.setAttribute('aria-live', 'assertive');
	div.setAttribute('aria-atomic', 'true');
	div.className = 'astro-route-announcer';
	document.body.append(div);
	setTimeout(
		() => {
			let title = document.title || document.querySelector('h1')?.textContent || location.pathname;
			div.textContent = title;
		},
		// Much thought went into this magic number; the gist is that screen readers
		// need to see that the element changed and might not do so if it happens
		// too quickly.
// ... (674 more lines)

Domain

Subdomains

Dependencies

  • ../../transitions/events.js
  • ./swap-functions.js
  • ./types.js
  • client

Frequently Asked Questions

What does router.ts do?
router.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in router.ts?
router.ts defines 16 function(s): abortAndRecreateMostRecentNavigation, announce, fetchHTML, getFallback, moveToLocation, navigate, onPopState, onScrollEnd, preloadStyleLinks, prepareForClientOnlyComponents, and 6 more.
What does router.ts depend on?
router.ts imports 4 module(s): ../../transitions/events.js, ./swap-functions.js, ./types.js, client.
Where is router.ts in the architecture?
router.ts is located at packages/astro/src/transitions/router.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/transitions).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free