reactjs - 如何在下一个js中设置默认页面?
问题描述
我是新手next.js
,在next.js
默认页面中index.js
,我想将其路径更改为login
,有人可以帮我怎么做吗?现在我正在使用Router.push('/login');
,但它正在产生闪烁问题,有人可以帮忙解决这个问题吗?
import Head from 'next/head'
import styles from '../styles/Home.module.css'
import Router from 'next/router'
import React, { useEffect } from "react";
import { Redirect } from 'react-router';
export default function Home(props) {
useEffect(() => {
const { pathname } = Router
if (pathname == '/') {
Router.push('/login');
}
}, [props]);
return ''
}
解决方案
您可以像这样添加redirects
到您的next.config.js
:
module.exports = {
async redirects() {
return [
{
source: '/about',
destination: '/',
permanent: true,
},
]
},
}
推荐阅读
- excel - 使用用户表单更新现有行数据
- python-3.x - 使用配置文件从 python 连接到 oracle db
- vuejs2 - 包含 fetch 的方法不会改变对象的值
- php - 24 小时后更新特定用户行
- android - 如何避免 32 位 Linux 内核的虚拟碎片问题?
- javascript - URL 处的 GeoJSON 刚刚停止渲染标记
- php - Install mailgun bundle in Symfony 3.4 but getting unrecognized option "endpoint" error
- c++ - C++:在函数参数的上下文中,`const T &` 和 `T &&` 有什么区别?
- php - PHP:检测浏览器语言和重定向的正确方法
- java - 机器人类不能在 selenium webdriver 的 for 循环中工作,以便代码一个接一个地上传文件