我正在开发一个 Ionic Aungular PWA 项目,并且在 Chrome 中始终遇到失败的 Lighthouse 审核,并显示 404 错误,指出无法找到我重定向到的默认路径(本例中为 /home)的 localhost 页面。我在下面包含了自动生成的 src/app/app-routing.module.ts 文件。如果我替换重定向路径来加载 \xe2\x80\x9chome\xe2\x80\x9d 模块而不是重定向到主路径,则审核成功。任何人都可以帮助解释为什么redirectTo 不起作用吗?
\nimport { NgModule } from '@angular/core';\nimport { PreloadAllModules, RouterModule, Routes } from '@angular/router';\n\nconst routes: Routes = [\n {\n path: 'home',\n loadChildren: () => import('./pages/home/home.module').then( m => m.HomePageModule)\n },\n {\n path: '',\n redirectTo: 'home',\n pathMatch: 'full'\n },\n {\n path: 'create-restaurant-menu',\n loadChildren: () => import('./pages/page2/page2.module').then( m => m.Page2Model)\n }\n];\n\n@NgModule({\n imports: [\n RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })\n ],\n exports: [RouterModule]\n})\nexport class AppRoutingModule { …Run Code Online (Sandbox Code Playgroud) 我是一名经验丰富的前端开发人员,但我对 Ionic 很陌生,所以请原谅我问了一个愚蠢的问题。
我正在使用 Ionic-Vue 创建移动应用程序。
我从选项卡默认模板开始。我可以毫无问题地在选项卡之间切换:每个选项卡都有关联的路线和组件,并且当我切换选项卡时会立即显示正确的组件。
现在来说说问题。
我正在尝试为登录屏幕添加新的路由/组件。我希望登录屏幕位于选项卡系统之外,因此我将其作为顶级路由“/login”及其关联组件。我在第一个选项卡上添加了一个新按钮以便登录,这就是代码。
<ion-button href="/login">LOGIN</ion-button>
Run Code Online (Sandbox Code Playgroud)
但是,当我按下按钮时,整个页面都会重新加载,切换组件所需的时间比我浏览不同选项卡时要多得多。在我看来,它没有使用内部路由器,而是更改了页面的实际 URL,导致整个应用程序再次向服务器请求。我认为这与我使用选项卡默认模板有关,也许如果您使用选项卡就不能拥有独立的路由?
这是我的路由表:
const routes: Array<RouteRecordRaw> = [
{
path: '/',
redirect: '/tabs/home'
},
{
path: '/tabs/',
component: Tabs,
children: [
{
path: '',
redirect: 'home'
},
{
path: 'home',
component: () => import('@/views/Home.vue')
},
{
path: 'tab1',
component: () => import('@/views/Tab1.vue')
},
{
path: 'tab2',
component: () => import('@/views/Tab2.vue')
},
{
path: 'tab3',
component: () => import('@/views/Tab3.vue')
}
]
},
{
path: '/login',
component: () => …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现 Capacitor LocalNotification 插件。
\nimport { Plugins, CameraResultType } from '@capacitor/core';\nconst { LocalNotifications } = Plugins;\nRun Code Online (Sandbox Code Playgroud)\n在下面的代码中就像
\n schedule() {\n console.log('----')\n LocalNotifications.schedule({\n notifications: [\n {\n title: "aaaa",\n body: "Body",\n id: 1,\n smallIcon: 'house',\n actionTypeId: 'OPEN_PRODUCT',\n \n schedule: {\n every: "minute"\n },\n\n extra: null\n }\n ]\n });\n }\nRun Code Online (Sandbox Code Playgroud)\n我正在 ios 模拟器上进行测试,该方法被调用,在 Xcode-debug 中我得到这样的结果:
\n To Native -> LocalNotifications schedule 1850642\n\xe2\x9a\xa1\xef\xb8\x8f TO JS {"notifications":[{"id":"1"}]\nRun Code Online (Sandbox Code Playgroud)\n但模拟器中未显示通知。
\n我在这个项目中没有使用 cordova/ionic-native 。如果我需要运行一些 npm 包等才能使其正常工作,请提供帮助。
\n我正在尝试使用 Angular 11 和 ionic 5 构建一个社交共享组件。我使用锚标记来调用 href="whatsapp://send?#text=some%20text"。这在安装了 WhatsApp 的设备上运行良好,但在未安装 WhatsApp 的设备上,我仅在浏览器控制台中收到以下错误:
无法启动“whatsapp://send?#text=text=some%20text”,因为该方案没有注册处理程序。
我怎样才能捕捉到这个错误,向用户显示一条友好的消息,例如“抱歉,您没有安装 WhatsApp”
我的 Ionic 5 和 Angular 应用程序有一个小问题。
\n所以,我有一个离子段,但我不可能更改处于活动/选中状态的段按钮的背景颜色。
\n除了官方文档之外,我尝试了在论坛上阅读的许多不同方法,但仍然不可能。
\n你能帮我吗?
我的 home.html 中的离子段:
\n<ion-segment value=\'favorites\' [(ngModel)]="segmentModel" (ionChange)="segmentChanged($event)" color="maindark" mode=\'ios\' swipeGesture=\'true\' scrollable=\'true\'>\n <ion-segment-button value="favorites">\n <ion-label>Favoris</ion-label>\n </ion-segment-button>\n <ion-segment-button value="settings">\n <ion-label>Param\xc3\xa8tres</ion-label>\n </ion-segment-button>\n</ion-segment>\nRun Code Online (Sandbox Code Playgroud)\nhome.scss 中该段的 SCSS:
\nion-segment {\n padding: 5px 0 5px 0;\n margin: 5vh 15vw 0 15vw;\n background-color: #2d303aab;\n}\n\nion-segment-button {\n padding: 7px 0 7px 0;\n font-size: 16px;\n color: white;\n}\n\n.segment-button-checked {\n color: #F8CF80 !important; // it works properly \n\n // Tried all of that but nothing work\n background-color: #2D303A !important; \n …Run Code Online (Sandbox Code Playgroud) 我正在使用 Capacitor、Ionic、React 开发一个应用程序,最近我在第一次使用 React Hook Form 和 YupResolver 时遇到以下错误:
当我尝试运行该项目时,出现以下错误:
Failed to compile
./node_modules/@hookform/resolvers/dist/resolvers.module.js
Attempted import error: 'set' is not exported from 'react-hook-form' (imported as 'o').
Run Code Online (Sandbox Code Playgroud)
我想创建并验证用于更改密码的表单,将新密码提交到外部 API /change-password。表格如下所示:
Actual Password: ...
New Password: ...
Confirm new Password: ...
Submit
Run Code Online (Sandbox Code Playgroud)
组件:
import {
IonContent,
IonPage,
IonItem,
IonLabel,
IonButton,
IonInput,
IonRow,
IonAlert,
IonGrid,
IonCol,
} from "@ionic/react";
import React, { useState } from "react";
import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";
import * as yup from …Run Code Online (Sandbox Code Playgroud) .html
<ion-radio-group
*ngFor="let option of data"
(ionChange)="checkValue($event)"
[value]="item">
<ion-item>
<ion-label>{{option.optionA}}</ion-label>
<ion-radio slot="start" value="Not"></ion-radio>
</ion-item>
<ion-item>
<ion-label>{{option.optionB}}</ion-label>
<ion-radio slot="start" value="Some"></ion-radio>
</ion-item>
<ion-item>
<ion-label>{{option.optionC}}</ion-label>
<ion-radio slot="start" value="Most"></ion-radio>
</ion-item>
<ion-item>
<ion-label>{{option.optionD}}</ion-label>
<ion-radio slot="start" value="All"></ion-radio>
</ion-item>
</ion-radio-group>
<div class="evalbtn">
<button (click)="print(event)" class="nextbtn" (click)="evaluation2()">
Submit
</button>
</div>
Run Code Online (Sandbox Code Playgroud)
.ts
data: any[] = [
{
"optionA":"Not at All",
"optionB":"For some of the Time",
"optionC":"For most of the Time",
"optionD":"For all of the Time",
}
];
//function to print what is inputed in the form that is declared …Run Code Online (Sandbox Code Playgroud) 我添加了一个上下文,其中包含useReducer我的 Ionic React 应用程序的钩子。我看到一些奇怪的行为:当我通过调用更新上下文值时dispatch,页面上的消费者组件将被更新,但选项卡栏上完全相同的组件不会更新。
我按照这个教程进行了操作。
当我添加console.log语句来检查组件是否正在重新加载时,我发现<TabBarCounter>即使上下文值已更改,放置在选项卡栏 ( ) 中的组件也没有重新加载。
当我添加语句来检查上下文提供程序中的重新渲染时,我发现调用console.loga 时它也不会重新渲染。dispatch
上下文似乎是在本地更新,而不是全局更新。这个答案中有一条评论:
您正在使用减速器正确更新状态,但它只会更新本地组件状态,而不是全局上下文状态。
这听起来很像我在这里遇到的问题。
这是一些代码:
MyContext.tsx
export const CountContext = React.createContext<any>({} as {
countState: CountState,
countDispatch: React.Dispatch<CountReducerActions>,
});
interface MyProps {
children: JSX.Element,
}
const reducer = (countState: CountState, action: CountReducerActions) => {
switch (action.type) {
case 'add1': {
countObject.total += 1;
return countObject;
}
default: {
throw new Error();
}
}
};
export const …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 android 平台添加到 Ionic(Angular)项目中。
ionic capacitor add android
Run Code Online (Sandbox Code Playgroud)
它识别离子电容器添加并要求我选择一个平台。
? What platform would you like to add? (Use arrow keys)
> android
ios
Run Code Online (Sandbox Code Playgroud)
但是当我选择 android 平台时,我就会收到此错误。
? What platform would you like to add? android
[ERROR] Error while getting Capacitor CLI version.
'capacitor' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)
问题是什么?我该怎么办?任何帮助表示赞赏。谢谢。
我刚刚通过运行升级了我的 Angular ionic 应用程序,以使用 Angular 12 中的 Angular v13 ng update。更新成功,但现在我无法运行该应用程序,并出现以下错误
[ng] Error: node_modules/ionicons/dist/types/components.d.ts:66:15 - error TS2320: Interface 'HTMLIonIconElement' cannot simultaneously extend types 'IonIc
on' and 'HTMLStencilElement'.
[ng] Named property 'ariaHidden' of types 'IonIcon' and 'HTMLStencilElement' are not identical.
[ng]
[ng] 66 interface HTMLIonIconElement extends Components.IonIcon, HTMLStencilElement {
[ng] ~~~~~~~~~~~~~~~~~~
[ng]
[ng]
[ng] Error: node_modules/ionicons/dist/types/components.d.ts:66:15 - error TS2320: Interface 'HTMLIonIconElement' cannot simultaneously extend types 'IonIc
on' and 'HTMLStencilElement'.
[ng] Named property 'ariaLabel' of types 'IonIcon' and 'HTMLStencilElement' are not …Run Code Online (Sandbox Code Playgroud) ionic-framework ×10
angular ×7
typescript ×3
capacitor ×2
javascript ×2
reactjs ×2
angular13 ×1
browser ×1
ionic-react ×1
ionic-vue ×1
lighthouse ×1
properties ×1
radio-button ×1
react-hooks ×1
segment ×1
use-reducer ×1
vue-router ×1
vue.js ×1
whatsapp ×1
yup ×1