Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Navigation and routing

Navigation means moving to another location or view, while routing maps a path to its handling logic. Neither is a separate ECMAScript syntax construct. The example demonstrates route selection only, without changing the browser address.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

function resolveRoute(path) { switch (path) { case "/": return "Home"; case "/help": return "Help"; default: return "Not found"; } }

Navigation means moving to another location or view. Routing means the rules that select handling logic for a given path. Separate these responsibilities: determining what corresponds to a path is not yet performing the transition or displaying content.

ECMAScript defines the language, while the host environment supplies additional capabilities. The specification describes this boundary in “Web Scripting” and “Hosts and Implementations”. Navigation and routing have no single special ECMAScript syntax. The supplied sources do not document browser navigation API contracts or compatibility; this entry makes no support claim for those APIs. Having Node 24 in a repository does not establish browser API availability.

In the example, resolveRoute(path) is an application-defined function, not a built-in router. switch selects a result for an exact string match, and return ends the call. default supplies a result for an unknown path. The function changes neither the address, history, nor page content.

The example deliberately has a narrow contract: its input is only a path. /help/ and /help are different inputs; queries and fragments are not parsed. When extending it, define normalization and unknown-route handling, and treat browser integration as a separate layer requiring Web APIs documentation.

Examples

function resolveRoute(path) {
  switch (path) {
    case "/":
      return "Home";
    case "/help":
      return "Help";
    default:
      return "Not found";
  }
}

console.log(resolveRoute("/"));
console.log(resolveRoute("/help"));
console.log(resolveRoute("/missing"));

Result

Home
Help
Not found

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources