# angularDemo **Repository Path**: pampus/angularDemo ## Basic Information - **Project Name**: angularDemo - **Description**: angular简单Demo - **Primary Language**: TypeScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2017-02-10 - **Last Updated**: 2022-06-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 路由 -- url 访问路径,配置文件为app.routing.ts,pages.routing.ts和*.routing.ts , app.routing.ts 基本不用动, pages.routing.ts是主页路由,主要是首页菜单路由, *.routing.ts 例如 const routes: Routes = [ { path: '', component: Tables, children: [ { path: 'bookManage', component: BasicTables }, { path: 'borrowRecord', component: SmartTables } -----------------这里-------------------- ] } ]; 就是每个页面的路由配置,每个 module 建议单独配置一个 routing.ts 文件 主页菜单路由需要在 pages.routing.ts 中给children加相应的moudle 就好 { path: 'pages', component: Pages, children: [ {path: 'login', loadChildren: () => System.import('./login/login.module')}, {path: 'bookList', loadChildren: () => System.import('./bookList/tables.module')} -----------------这里-------------------- ] } 菜单 -- 动态配置是在登录之后返回的菜单 json 数据 在login.service.ts中 login(loginInfo:any):Promise { const url = "/test/login.json"; return this.http .get(url) .toPromise() .then(response => response.json() as any); } 注意返回的menu 格式 登录 -- login.component.ts 中.登录后用户信息放在 localStorage里面,token 等信息后台写入 cookie 里面,时间为 session 且为http安全的.这里验证判断没有写详细. public onSubmit(values:Object):void { this.submitted = true; if (this.form.valid) { if (this.form.value.username != "admin" || this.form.value.password != "admin") { alert("用户名或密码错误,默认 admin"); return; } this.loginService.login(this.form.value).then((data) => { if (data.code == "success") { localStorage.setItem("menu", JSON.stringify(data.menu)); localStorage.setItem("userinfo", JSON.stringify(data.user)); location.href = '#/pages/bookList/bookManage'; } else { alert("用户名或密码错误"); } console.info(data); }); } }