首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nativescript找不到模块'@nativescript/angular/router‘

Nativescript找不到模块'@nativescript/angular/router‘
EN

Stack Overflow用户
提问于 2020-12-29 18:53:34
回答 1查看 741关注 0票数 0

我正在开发一个应用程序使用nativescript和角度11.0。对于初始启动,创建登录屏幕。在运行应用程序时遇到问题。获取下面的异常。只有在模块中启用了路由时,才会出现此问题。

代码语言:javascript
复制
ERROR in ./app/login/login.component.ts
Module not found: Error: Can't resolve '@nativescript/angular/router' in 'D:\Mobile_dev\ns-ng-quiz\app-ns-ng\src\app\login'
     @ ./app/login/login.component.ts 3:0-64 5:0-51 40:113-132 78:38-57
     @ ./app/app.module.ts
     @ ./main.ts   

ng update说一切正常。删除node_modules文件夹和重新安装npm也没有帮助。

这是我的package.json

代码语言:javascript
复制
{
      "name": "@nativescript/template-hello-world-ng",
      "main": "main.js",
      "version": "7.0.8",
      "author": "NativeScript Team <oss@nativescript.org>",
      "description": "NativeScript Application",
      "license": "SEE LICENSE IN <your-license-filename>",
      "publishConfig": {
        "access": "public"
      },
      "keywords": [
        "nativescript",
        "mobile",
        "angular",
        "{N}",
        "template"
      ],
      "repository": {
        "type": "git",
        "url": "<fill-your-repository-here>"
      },
      "bugs": {
        "url": "https://github.com/NativeScript/NativeScript/issues"
      },
      "dependencies": {
        "@angular/animations": "~11.0.0",
        "@angular/common": "~11.0.0",
        "@angular/compiler": "~11.0.0",
        "@angular/core": "~11.0.0",
        "@angular/forms": "~11.0.0",
        "@angular/platform-browser": "~11.0.0",
        "@angular/platform-browser-dynamic": "~11.0.0",
        "@angular/router": "~11.0.0",
        "@nativescript/angular": "~11.0.0",
        "@nativescript/core": "~7.0.0",
        "@nativescript/theme": "~3.0.0",
        "reflect-metadata": "~0.1.12",
        "rxjs": "^6.6.0",
        "zone.js": "~0.11.1"
      },
      "devDependencies": {
        "@angular/compiler-cli": "~11.0.0",
        "@nativescript/android": "7.0.1",
        "@nativescript/types": "~7.0.0",
        "@nativescript/webpack": "~3.0.0",
        "@ngtools/webpack": "~11.0.0",
        "typescript": "~4.0.0"
      },
      "private": "true",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      }
    }

这是我的app-routing.module.ts

代码语言:javascript
复制
import { LoginComponent } from './login/login.component';
import { HomeComponent } from './home/home.component';
import { NgModule } from "@angular/core";
import { Routes } from "@angular/router";
import { NativeScriptRouterModule } from "@nativescript/angular";

import { ItemsComponent } from "./item/items.component";
import { ItemDetailComponent } from "./item/item-detail.component";

const routes: Routes = [
    
    {path: "", redirectTo: "/login", pathMatch: "full" },
    {path:"login", component:LoginComponent},
    {path:"home", component:HomeComponent}
   //{ path: "", redirectTo: "/items", pathMatch: "full" },
   // { path: "items", component: ItemsComponent },
   // { path: "item/:id", component: ItemDetailComponent }
   
];

@NgModule({
    imports: [NativeScriptRouterModule.forRoot(routes,{
        enableTracing:true
    })],
    exports: [NativeScriptRouterModule]
})
export class AppRoutingModule { }

VSCode中的项目结构

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-31 14:50:52

您应该能够从@nativescript/angular导入用于导航的RouterExtensions和模块中的NativeScriptRouterModule,而不是以前的@nativescript/angular/router路径。

代码语言:javascript
复制
import { RouterExtensions } from '@nativescript/angular'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65490986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档