Б
Size: a a a
Б
Б
🦜
▲
▲
▲
EM
import Router from 'next/router';
const handleRedirect = ({ res, query: { type, destination } }) => {
if (type === 'redirect') {
if (res && destination) {
res.writeHead(302, {
Location: destination,
});
res.end();
} else {
Router.push(destination);
}
}
};
export default handleRedirect;
А
▲
▲
А
Б
if (!ctx.req && !token) {
Router.push('/login')
}
Б
🦜
if (!ctx.req && !token) {
Router.push('/login')
}
Б
▲R
if (!ctx.req && !token) {
Router.push('/login')
}
▲R
▲R
▲R
// redirectTo.js
import Router from 'next/router'
export default function redirectTo(
destination,
{ as, res, status } = {},
replace = false
) {
if (res) {
res.writeHead(status || 302, { Location: as || destination })
res.end()
return
} else {
if (destination[0] === '/' && destination[1] !== '/') {
if (replace) {
return Router.replace(destination, as)
} else {
return Router.push(destination, as)
}
} else {
window.location = destination
return
}
}
}
s и
з getInitialProps,
на клиенте нет🦜