Skip to content

Path and domain

A cookie is only visible on pages under its path. The browser also treats cookies with the same name but a different path as separate cookies, so delete() must use the same path that set() used.

Try it:

  1. Click set() on path: '/somewhere-else'. The cookie is written, but this page can’t see it.
  2. Click set() on path: '/', then delete() on the “no path” row. Nothing is deleted, because the paths don’t match.
  3. Click delete() on path: '/'.
Live demo

domain makes a cookie visible to subdomains. { domain: 'example.com' } set from app.example.com is also sent to api.example.com. Without domain, the cookie belongs to the current host only.

  • If path or domain contains ; or a control character, the call is skipped with a console warning. That stops a value from injecting extra cookie attributes.
  • Set path: '/' once for the whole app with provideCookieOptions().