@mdguggenbichler/slugbase-core 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -229,6 +229,7 @@ export interface AppProps {
229
229
 
230
230
  function App({ basePath, apiBaseUrl, routerBasename, skipSetupFlow }: AppProps = {}) {
231
231
  const appRootPath = basePath === '/' || !basePath ? '/' : basePath;
232
+ const pathPrefixForLinks = routerBasename !== undefined ? '' : (basePath ?? '');
232
233
  const content = (
233
234
  <AuthProvider>
234
235
  <TooltipProvider>
@@ -240,7 +241,7 @@ function App({ basePath, apiBaseUrl, routerBasename, skipSetupFlow }: AppProps =
240
241
  );
241
242
  return (
242
243
  <AppErrorBoundary>
243
- <AppConfigProvider appBasePath={basePath} apiBaseUrl={apiBaseUrl} appRootPath={appRootPath} skipSetupFlow={skipSetupFlow}>
244
+ <AppConfigProvider appBasePath={basePath} apiBaseUrl={apiBaseUrl} appRootPath={appRootPath} skipSetupFlow={skipSetupFlow} pathPrefixForLinks={pathPrefixForLinks}>
244
245
  {routerBasename !== undefined ? (
245
246
  content
246
247
  ) : (
@@ -7,12 +7,15 @@ export interface AppConfig {
7
7
  appRootPath: string;
8
8
  /** When true, skip the first-time setup flow (e.g. in cloud; first user registers via Signup). */
9
9
  skipSetupFlow?: boolean;
10
+ /** Prefix for Link/Navigate paths. Empty when under external Router (e.g. cloud basename="/app"); otherwise appBasePath. Use for all in-app navigation. */
11
+ pathPrefixForLinks: string;
10
12
  }
11
13
 
12
14
  const defaultConfig: AppConfig = {
13
15
  appBasePath: defaultAppBasePath,
14
16
  apiBaseUrl: defaultApiBaseUrl,
15
17
  appRootPath: defaultAppRootPath,
18
+ pathPrefixForLinks: defaultAppBasePath,
16
19
  };
17
20
 
18
21
  const AppConfigContext = createContext<AppConfig>(defaultConfig);
@@ -23,18 +26,23 @@ export function AppConfigProvider({
23
26
  apiBaseUrl,
24
27
  appRootPath,
25
28
  skipSetupFlow,
29
+ pathPrefixForLinks,
26
30
  }: {
27
31
  children: React.ReactNode;
28
32
  appBasePath?: string;
29
33
  apiBaseUrl?: string;
30
34
  appRootPath?: string;
31
35
  skipSetupFlow?: boolean;
36
+ /** When set (e.g. "" when under external Router), used for Link/Navigate. Omit to use appBasePath. */
37
+ pathPrefixForLinks?: string;
32
38
  }) {
39
+ const base = appBasePath ?? defaultConfig.appBasePath;
33
40
  const value: AppConfig = {
34
- appBasePath: appBasePath ?? defaultConfig.appBasePath,
41
+ appBasePath: base,
35
42
  apiBaseUrl: apiBaseUrl ?? defaultConfig.apiBaseUrl,
36
43
  appRootPath: appRootPath ?? defaultConfig.appRootPath,
37
44
  skipSetupFlow,
45
+ pathPrefixForLinks: pathPrefixForLinks !== undefined ? pathPrefixForLinks : base,
38
46
  };
39
47
  return <AppConfigContext.Provider value={value}>{children}</AppConfigContext.Provider>;
40
48
  }
@@ -9,7 +9,7 @@ const MIN_PASSWORD_LENGTH = 8;
9
9
 
10
10
  export default function Signup() {
11
11
  const { t } = useTranslation();
12
- const { appBasePath } = useAppConfig();
12
+ const { pathPrefixForLinks } = useAppConfig();
13
13
  const [email, setEmail] = useState('');
14
14
  const [name, setName] = useState('');
15
15
  const [password, setPassword] = useState('');
@@ -60,7 +60,7 @@ export default function Signup() {
60
60
  {t('signup.successMessage')}
61
61
  </p>
62
62
  <Link
63
- to={`${appBasePath}/login`}
63
+ to={`${pathPrefixForLinks}/login`}
64
64
  className="inline-flex items-center justify-center px-4 py-2 text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-lg"
65
65
  >
66
66
  {t('signup.backToLogin')}
@@ -188,7 +188,7 @@ export default function Signup() {
188
188
  </form>
189
189
  <p className="mt-4 text-center text-sm text-gray-600 dark:text-gray-400">
190
190
  {t('signup.alreadyHaveAccount')}{' '}
191
- <Link to={`${appBasePath}/login`} className="font-medium text-blue-600 dark:text-blue-400 hover:underline">
191
+ <Link to={`${pathPrefixForLinks}/login`} className="font-medium text-blue-600 dark:text-blue-400 hover:underline">
192
192
  {t('signup.logIn')}
193
193
  </Link>
194
194
  </p>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdguggenbichler/slugbase-core",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "SlugBase core: backend and frontend entrypoints for self-hosted and cloud apps",
5
5
  "type": "module",
6
6
  "exports": {