【发布时间】:2018-04-05 06:11:27
【问题描述】:
我正在尝试将普通引导模板转换为角度网站。我在从一个页面导航到另一个页面时遇到路由问题,例如About 到Contact,反之亦然。
模板已经有以下格式,在hashtag #的帮助下使用了一些css来平滑滚动。
我的 app.compo.html
之前:<li><a href="#header">About</a></li>
之后:<li><a routerLink="/about" routerLinkActive="active" href="#header">About</a></li>
<a href="#header" id="btp" class="back-to-top btn-floating waves-effect waves-light btn-large custom-btn">
<i class="ion-ios-arrow-up"></i>
</a>
app.routing.ts
const routes: Routes = [
{ path: '', redirectTo: 'about', pathMatch: 'full' },
{ path: 'about', component: about, data: { state: 'about'} },
{ path: 'contact', component: contact, data: { state: 'contact'} },
];
export const AppRouting = RouterModule.forRoot(routes, {
useHash: true
});
点击 npm start 后,它在我的控制台中显示如下
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2018-04-05T05:55:06.359Z
Hash: 0bace8e39ad063fd5145
Time: 3614ms
chunk {inline} inline.bundle.js (inline) 3.85 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 2.91 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 577 bytes [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 46 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 852 kB [initial] [rendered]
ERROR in Cannot read property 'length' of undefined
webpack: Failed to compile.
这是我第一次尝试使用 angular 2。我无法理解官方文档和其他相关主题的问题。
请指导我正确的方式。如果可能,请分享一些 plunker 或 stackblitz 示例
【问题讨论】:
-
我在代码中的任何地方都看不到
lengthused 属性!你能添加那个信息吗 -
@Aravind 。道歉。我真的不明白你说的财产是什么意思。?能解释一下我该怎么办吗?
-
您是在尝试重定向到不同的页面还是指向同一页面上的片段(带有# 的元素)?
标签: javascript html angular typescript