next.js

How to redirect to login page for restricted pages in next.js?

不问归期 提交于 2020-08-21 20:19:27
问题 In the udemy tutorial The Complete React Developer Course the additional package history was used to get the router outside a component for redirecting when the user is not authenticated: /* AppRouter.js */ import createHistory from "history/createBrowserHistory"; const AppRouter = () => ( <Router history={history}> <div> <Switch> <PublicRoute path="/" component={LoginPage} exact={true} /> <PrivateRoute path="/dashboard" component={ExpenseDashboardPage} /> <PrivateRoute path="/create"

How to redirect to login page for restricted pages in next.js?

蹲街弑〆低调 提交于 2020-08-21 20:19:04
问题 In the udemy tutorial The Complete React Developer Course the additional package history was used to get the router outside a component for redirecting when the user is not authenticated: /* AppRouter.js */ import createHistory from "history/createBrowserHistory"; const AppRouter = () => ( <Router history={history}> <div> <Switch> <PublicRoute path="/" component={LoginPage} exact={true} /> <PrivateRoute path="/dashboard" component={ExpenseDashboardPage} /> <PrivateRoute path="/create"

详解React 元素渲染

瘦欲@ 提交于 2020-08-20 01:29:11
元素是构成 React 应用的最小单位,它用于描述屏幕上输出的内容。 const element = <h1>Hello, world!</h1>; 与浏览器的 DOM 元素不同,React 当中的元素事实上是普通的对象,React DOM 可以确保 浏览器 DOM 的数据内容与 React 元素保持一致。 将元素渲染到 DOM 中 首先我们在一个 HTML 页面中添加一个 id="example" 的 <div> : <div id="example"></div> 在此 div 中的所有内容都将由 React DOM 来管理,所以我们将其称为 "根" DOM 节点。 我们用 React 开发应用时一般只会定义一个根节点。但如果你是在一个已有的项目当中引入 React 的话,你可能会需要在不同的部分单独定义 React 根节点。 要将React元素渲染到根DOM节点中,我们通过把它们都传递给 ReactDOM.render() 的方法来将其渲染到页面上: const element = <h1>Hello, world!</h1>; ReactDOM.render( element, document.getElementById('example') ); 更新元素渲染 React 元素都是不可变的。当元素被创建之后,你是无法改变其内容或属性的。

How to access Kubernetes container environment variables from Next.js application?

只愿长相守 提交于 2020-08-17 11:08:09
问题 In my next.config.js, I have a part that looks like this: module.exports = { serverRuntimeConfig: { // Will only be available on the server side mySecret: 'secret' }, publicRuntimeConfig: { // Will be available on both server and client PORT: process.env.PORT, GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID, BACKEND_URL: process.env.BACKEND_URL } I have a .env file and when run locally, the Next.js application succesfully fetches the environment variables from the .env file. I refer to the env

How to access Kubernetes container environment variables from Next.js application?

会有一股神秘感。 提交于 2020-08-17 11:07:16
问题 In my next.config.js, I have a part that looks like this: module.exports = { serverRuntimeConfig: { // Will only be available on the server side mySecret: 'secret' }, publicRuntimeConfig: { // Will be available on both server and client PORT: process.env.PORT, GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID, BACKEND_URL: process.env.BACKEND_URL } I have a .env file and when run locally, the Next.js application succesfully fetches the environment variables from the .env file. I refer to the env

基于 Next.js 和云开发 CMS 的内容型网站应用实战开发

亡梦爱人 提交于 2020-08-17 08:43:46
作者简介 : 董沅鑫,云开发 CloudBase 团队研发工程师,侧重于前端工程化、node 服务开发,业余时间出没在 xin-tan.com。 本文目录 : 引言 总览 背景介绍 安装 CMS 使用 CMS 创建动态内容 项目搭建 获取 CMS 内容 自动构建与部署 最后 引言 随着腾讯云云开发能力的日渐完善,有经验的工程师已经可以独立完成一个产品的开发和上线。 但网上云开发相关的实战文章非常少,很多开发者清楚云开发的能力,但是不清楚如何在现有的开发体系下引入云开发 。 本文从云开发团队开发者+能力使用者的角度,以云开发官网 ( cloudbase.net/ ) 的搭建思路为例,分享云开发结合流行框架与工具的实战经验。 涉及到的知识点有 : 云开发: 扩展能力(CMS 扩展) 静态托管 云数据库 CloudBase CLI 工具 React 框架:Next.js CI 自动构建 总览 系统设计图 : 背景介绍 随着云开发团队业务的迅猛发展,团队需要一个官网来更直观、更即时地向开发者们展示云开发的相关能力,包括但不限于工具链、SDK、技术文档等。 同时,为了降低开发者的上手成本,积累业界的优秀实战经验,官网也承载着营造社区氛围、聚合重要资料、增强用户黏度的重要任务。 我们最初使用 VuePress 作为静态网站工具,遇到了一些痛点: 问题 1: 每次更新内容,都需要配合 git

腾讯云 Serverless 部署应用耗时降低了 73%

前提是你 提交于 2020-08-12 04:57:58
在使用 Serverless Framework 部署 Next.js,Egg.js 项目时,由于安装的依赖包过大,部署时压缩上传时间很长,可能出现上传超时、控制台卡死等问题。 为此,Serverless 团队近期对部署做了一个性能优化,原来部署一个 Next.js 的 Demo 项目大约需要 55s 左右,而现在只需要 18s 的时间。 下面我们一起看一下,优化前后部署方案哪些不同。 一、部署性能对比 本次提速主要做的是压缩上传性能的提升。优化后采用流式上传压缩,并直接在压缩包内注入组件代码,大大的提升了性能。选取三种不同大小的代码包进行测试,优化前后平均部署性能如下所示: 代码包大小(MB) 优化前(秒) 优化后(秒) 111 MB 55 s 18 s 216 MB 100 s 38 s 418 MB 185 s 70 s 可见,部署的整体性能提升了将近 3倍 !对于一个轻量级别的网站或博客( 200 MB 左右),每次部署只需要 35s 左右的时间! 二、CLI 控制台输出对比 在 CLI 控制台输入 sls deploy 命令后,CLI 控制台状态的对比,如下图所示: 优化前部署全流程仅有 deploying 状态,直到部署结束返回结果。优化后将部署流程的每一步实时反馈到控制台界面上,让用户更清晰的看到整个部署流程,也能方便定位问题(如本地网络问题导致上传失败)。

Next.js Link prefetch results in 404 in production

扶醉桌前 提交于 2020-08-10 18:55:18
问题 I'm practising Next.js with this project https://github.com/YuLogun/nextjs-app-coctails (online - https://nextjs-app-coctails.vercel.app/) The thing I can't seem to resolve now is the following: when I type in the input field any cocktail name, the routing and linking works, new content appears, but I get this error in the console GET https://nextjs-app-coctails-git-addssr.yulogun.vercel.app/_next/static/rRHX14sSLtcEaeP7a3OxS/pages/cocktails/lemonade.js net::ERR_ABORTED 404 When I click the

Next.js Link prefetch results in 404 in production

一曲冷凌霜 提交于 2020-08-10 18:55:15
问题 I'm practising Next.js with this project https://github.com/YuLogun/nextjs-app-coctails (online - https://nextjs-app-coctails.vercel.app/) The thing I can't seem to resolve now is the following: when I type in the input field any cocktail name, the routing and linking works, new content appears, but I get this error in the console GET https://nextjs-app-coctails-git-addssr.yulogun.vercel.app/_next/static/rRHX14sSLtcEaeP7a3OxS/pages/cocktails/lemonade.js net::ERR_ABORTED 404 When I click the

Nextjs page goes to 404 on refresh

谁都会走 提交于 2020-08-10 08:50:11
问题 I'm using nextjs and graphql for a shopify POC. I have a component that shows a list of products with links on them that point to the product page <Link as={`${handle}/product/${url}`} href={`/product?id=${item.id};`}> <a>{item.title}</a> </Link> handle is the collection name so the url in the browser will look like http://localhost:3000/new-releases/product/Plattan-2-Bluetooth but behind the scenes its really just using a page called products and i'm passing the product id. Now in product.js