1
0
Fork 0
mirror of https://github.com/kou029w/_.git synced 2025-02-24 17:55:16 +00:00

fix base path

This commit is contained in:
Nebel 2020-02-09 00:07:54 +09:00
parent 5ad0195078
commit 301bd89c75
3 changed files with 38 additions and 7 deletions

View file

@ -1,6 +1,9 @@
const NEXT_BASE_PATH = process.env.NEXT_ASSET_PREFIX || "";
module.exports = require("@next/mdx")({ module.exports = require("@next/mdx")({
extension: /\.mdx?$/ extension: /\.mdx?$/
})({ })({
pageExtensions: ["ts", "tsx", "md", "mdx"], pageExtensions: ["ts", "tsx", "md", "mdx"],
assetPrefix: process.env.NEXT_ASSET_PREFIX || "" assetPrefix: NEXT_BASE_PATH,
env: { NEXT_BASE_PATH }
}); });

View file

@ -11,6 +11,15 @@ import Head from "next/head";
import Link from "next/link"; import Link from "next/link";
import TopAppBar from "./TopAppBar"; import TopAppBar from "./TopAppBar";
const isValidURL = (url: string) => {
try {
new URL(url);
} catch {
return false;
}
return true;
};
export const theme = createMuiTheme({ export const theme = createMuiTheme({
palette: { palette: {
primary: { primary: {
@ -39,11 +48,17 @@ export const components = {
h4: (props: {}) => <Typography component="h4" variant="h6" {...props} />, h4: (props: {}) => <Typography component="h4" variant="h6" {...props} />,
h5: (props: {}) => <Typography component="h5" variant="h6" {...props} />, h5: (props: {}) => <Typography component="h5" variant="h6" {...props} />,
h6: (props: {}) => <Typography variant="h6" {...props} />, h6: (props: {}) => <Typography variant="h6" {...props} />,
a: ({ href, ...props }: { href: string }) => ( a: ({ href, ...props }: { href: string }) => {
<Link prefetch href={href}> const url = isValidURL(href)
<MuiLink variant="body1" color="secondary" href={href} {...props} /> ? href
: `${process.env.NEXT_BASE_PATH}${href}`;
return (
<Link prefetch href={href} as={url}>
<MuiLink variant="body1" color="secondary" href={url} {...props} />
</Link> </Link>
) );
}
}; };
const MainTheme: React.FC = ({ children }) => ( const MainTheme: React.FC = ({ children }) => (

View file

@ -1,5 +1,6 @@
import React from "react"; import React from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import Link from "next/link";
import AppBar from "@material-ui/core/AppBar"; import AppBar from "@material-ui/core/AppBar";
import Tabs from "@material-ui/core/Tabs"; import Tabs from "@material-ui/core/Tabs";
import Tab from "@material-ui/core/Tab"; import Tab from "@material-ui/core/Tab";
@ -24,7 +25,19 @@ const TopAppBar = () => {
textColor="primary" textColor="primary"
> >
{routes.map(({ pathname, icon }) => ( {routes.map(({ pathname, icon }) => (
<Tab key={pathname} value={pathname} icon={icon} /> <Tab
key={pathname}
value={pathname}
icon={icon}
component={props => (
<Link
href={pathname}
as={`${process.env.NEXT_BASE_PATH}${pathname}`}
>
<a {...props} />
</Link>
)}
/>
))} ))}
</Tabs> </Tabs>
</AppBar> </AppBar>