How to override and combine client & server routing #605
-
Hi, first of all thanks for the great framework, I'm exploring VPS and have questions about routing & sharing the code. Let's imagine situations:
Everything is ok, we can override clientRouting in
So I have next questions:
For example I want to have a function which navigates whatever router is used on a page: import { navigate } from 'vite-plugin-ssr/client/router';
import { isBrowser } from '#shared/utils';
type NavigateParams = Parameters<typeof navigate>;
type NavigateReturn = ReturnType<typeof navigate>;
const completed = Promise.resolve();
/** Navigates to the url */
export function goto(url: string, parameters?: NavigateParams[1]): NavigateReturn {
// if it is not browser => do nothing
if (!isBrowser) {
return completed;
}
// contains scheme:// so it's an external url, navigate through redirect
if (url.indexOf(':') > 0) {
window.location.href = url;
return completed;
}
const href = url.startsWith('/') ? `${basePath}/${url.slice(1)}` : url;
// we should check it is client routing page or not
// implementation detail (!)
const globalNavigate = window['__vite_plugin_ssr']['navigate.ts']['navigate'];
if (globalNavigate.constructor.name === 'AsyncFunction') {
// we are on page with client-side routing, use navigate
return navigate(href, parameters);
}
// we are on page with server-side routing
else {
window.location.href = href;
}
return completed;
} Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
With V1 you'll be able to set VPS's navigation automatically knows whether the next page should be client-side routed or server-side routed. It should just work. If your company is up for it: https://github.com/sponsors/brillout. |
Beta Was this translation helpful? Give feedback.
With V1 you'll be able to set
clientRouting: false
.VPS's navigation automatically knows whether the next page should be client-side routed or server-side routed. It should just work.
If your company is up for it: https://github.com/sponsors/brillout.