Basic navigation with links
The simplest way to navigate is using standard HTML<a> tags. COSMOS RSC automatically intercepts clicks and performs client-side navigation:
Link component is needed - regular anchors work out of the box.
Programmatic navigation with useRouter
For client components that need to navigate programmatically, use the useRouter hook:
Router API
The router object provides:Adding view transitions
COSMOS RSC supports React’sViewTransition component for smooth animations during navigation.
NavigationTransition component
The demo includes aNavigationTransition component that wraps content for animated transitions:
app/components/navigation-transition.js
Using NavigationTransition in pages
Wrap page headings or sections withNavigationTransition for smooth transitions:
app/pages/features/forms.js
Defining transition animations
Define custom animations in yourglobals.css:
app/globals.css
How it works
COSMOS RSC’s client navigation:- Intercepts link clicks - The framework listens for clicks on
<a>tags - Updates the URL - Uses the Navigation API to change the browser URL
- Fetches RSC payload - Requests the new page as an RSC stream from the server
- Updates the UI - React renders the new page components
- Maintains state - Client components preserve their state during navigation
Navigation events
The Navigation API triggers view transitions automatically. COSMOS RSC leverages this to provide smooth animations without additional JavaScript.Best practices
Use semantic HTML
Use semantic HTML
Always use
<a> tags for navigation, not <button> or <div> with click handlers. This ensures:- Proper accessibility
- Right-click to open in new tab works
- Search engines can crawl your links
Keep transitions subtle
Keep transitions subtle
Use short durations (200-300ms) for navigation transitions. Long animations can feel sluggish.
Wrap key content in NavigationTransition
Wrap key content in NavigationTransition
Test without JavaScript
Test without JavaScript
COSMOS RSC pages work with JavaScript disabled - navigation falls back to full page loads. Test this to ensure your app remains accessible.
Example: Full navigation pattern
Here’s a complete example combining links, transitions, and the router:app/pages/index.js