---
title: "Discussion on \"next.js 13 App Router 正確監控路由變化：用 next/navigation 的 usePathname 取代 next/router\" | Hashnode"
description: "Discussion on \"next.js 13 App Router 正確監控路由變化：用 next/navigation 的 usePathname 取代 next/router\". Next.js 13 App Router 中，SPA 路由切換不會觸發 beforeunload。以 usePathname 監控 pathname 變化，在 useEffect 中處理 localStorage 保存；避免使用 next/router，以免出現 NextRouter was not moun"
url: "https://hashnode.com/posts/nextjs-13-app-router-nextnavigation-usepathname-nextrouter/690d5d70f1973ee086696a22"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [next.js 13 App Router 正確監控路由變化：用 next/navigation 的 usePathname 取代 next/router](https://yukki.hashnode.dev/nextjs-13-app-router-nextnavigation-usepathname-nextrouter?utm_source=hashnode&utm_medium=feed)

Next.js 13 App Router 中，SPA 路由切換不會觸發 beforeunload。以 usePathname 監控 pathname 變化，在 useEffect 中處理 localStorage 保存；避免使用 next/router，以免出現 NextRouter was not moun

Nov 7, 2025 · 1 min read · yukki.hashnode.dev  
Read the article

-   [#nextjs](https://hashnode.com/tag/nextjs)

## Written by

[Yukki Tsou](https://hashnode.com/@Yukki)

@Yukki · Taiwan

  
[View profile](https://hashnode.com/@Yukki)

F2E

一言敝之就是職業婦女。

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
