我有一个关于 Next.js 和 React 的项目,它不使用任何库进行路由。我应该如何为未经身份验证的用户实施路由保护(受保护的路由)?或者,如果 cookie 中没有令牌,我应该重定向它们吗?
我最近学到了一些关于fetch()和promise的知识,现在我需要在项目中使用它.这里我有一个fetch()函数,它运行得很好,但我想,它必须捕获一个错误.那么,在fetch()函数中捕获错误的最佳方法是什么?我需要在两个()中捕获它们?这里有一些代码:
const endpoint = 'http://localhost:3030/api/hotels';
const promise = fetch(endpoint)
.then(res => res.json(), err => {
console.log(err);
})
.then(parseRooms, err => {
console.log(err);
})
Run Code Online (Sandbox Code Playgroud)
谢谢 !
我有 3 个文件夹的项目(我正在使用 gulp),我不需要编译。所以,我需要一个任务,这需要3个文件夹"src/fonts","src/libs"并"src/docs"作为gulp.src(),只是移动它们在dest/文件夹中。我不需要对它们做任何事情,只需在构建后移动它们即可。
我目前的尝试:
gulp.task('others', function () {
return gulp.src(['src/libs/**'], ['src/fonts/**'], ['src/docs/**'])
.pipe(gulp.dest('dist/'))
});
Run Code Online (Sandbox Code Playgroud)
使用此代码,任务仅移动内部文件和文件夹(需要包装),并且仅将“src/libs”作为 gulp.src()
我有两个页面(diary.component和redactor.component)都绘制相同的组件food.component,只有很小的区别:如果是diary.component- 食物应该有一个"添加按钮".如果是redactor.component- 食物应该有一个删除按钮.我尝试在父组件中food.component.html使用boolean解决此问题,并使用*ngIf 检查此状态,但它不起作用.问题是什么,我该如何解决?这是我的代码,以便更好地理解:
diary.component.ts
isDiary: boolean;
ngOnInit() {
this.isDiary = true;
}
Run Code Online (Sandbox Code Playgroud)
food.component.html
<div class="food">
<button *ngIf="isDiary; else isRedactor" (click)="sendFood(food.name, food.nutritional_value)" class="add-btn" type="button">
<i class="fas fa-plus"></i>
</button>
<ng-template #isRedactor>
<button><i class="fas fa-times"></i></button>
</ng-template>
...
</div>
Run Code Online (Sandbox Code Playgroud)
谢谢 !
javascript ×2
angular ×1
angular5 ×1
boolean ×1
components ×1
directory ×1
es6-promise ×1
fetch ×1
fetch-api ×1
gulp ×1
libs ×1
next.js ×1
reactjs ×1
routes ×1
src ×1