File tree 1 file changed +15
-5
lines changed
1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,9 @@ pub fn use_resolved_path(
170
170
171
171
/// Returns a function that can be used to navigate to a new route.
172
172
///
173
+ /// This should only be called on the client; it does nothing during
174
+ /// server rendering.
175
+ ///
173
176
/// ```rust
174
177
/// # use leptos::{request_animation_frame, create_runtime};
175
178
/// # let runtime = create_runtime();
@@ -185,11 +188,18 @@ pub fn use_navigate() -> impl Fn(&str, NavigateOptions) {
185
188
move |to, options| {
186
189
let router = Rc :: clone ( & router. inner ) ;
187
190
let to = to. to_string ( ) ;
188
- request_animation_frame ( move || {
189
- if let Err ( e) = router. navigate_from_route ( & to, & options) {
190
- leptos:: debug_warn!( "use_navigate error: {e:?}" ) ;
191
- }
192
- } ) ;
191
+ if cfg ! ( any( feature = "csr" , feature = "hydrate" ) ) {
192
+ request_animation_frame ( move || {
193
+ if let Err ( e) = router. navigate_from_route ( & to, & options) {
194
+ leptos:: debug_warn!( "use_navigate error: {e:?}" ) ;
195
+ }
196
+ } ) ;
197
+ } else {
198
+ leptos:: warn!(
199
+ "The navigation function returned by `use_navigate` should \
200
+ not be called during server rendering."
201
+ ) ;
202
+ }
193
203
}
194
204
}
195
205
You can’t perform that action at this time.
0 commit comments