小编Alw*_*ard的帖子

Angular Universal在每个页面的页面源代码中呈现主页html

我的角度通用项目中有多个组件。当我从home组件路由到其他组件时,我只会在页面源中获取home组件的内容。路由组件未更新它。

我已经通过服务器端的console.log检查了是否每个组件都在服务器端呈现,但是它只是加载主页,其他组件没有在服务器端呈现。

我使用npm run build:ssr进行构建,使用npm run serve:ssr进行服务器端服务。

在cmd或浏览器控制台中运行上述命令时,也没有错误。

有人可以帮忙吗?我在这个问题上停留了大约一个星期。

如果您需要有关该项目的其他信息,请告诉我。

Package.json

"dependencies": {
    "@agm/core": "^1.0.0-beta.2",
    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/platform-server": "^5.2.8",
    "@angular/router": "^5.2.0",
    "@ngu/carousel": "^1.4.8",
    "@nguniversal/express-engine": "^5.0.0-beta.6",
    "@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.6",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "hammerjs": "^2.0.8",
    "ng2-nouislider": "^1.7.7",
    "ngx-bootstrap": "^2.0.0-beta.8",
    "nouislider": "^11.0.3",
    "reflect-metadata": "^0.1.12",
    "rxjs": "^5.5.6",
    "ts-loader": "^3.5.0",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular/cli": "~1.7.3",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60", …
Run Code Online (Sandbox Code Playgroud)

node.js express angular-universal angular angular5

6
推荐指数
1
解决办法
1099
查看次数

相同的路径和相同数量的参数,但在Angular 5应用程序中用于路由的组件不同

app.routing.module.ts

const routes: Routes = [
    { path: '', component: AComponent },
    ...
    { path: 'homes/:id/:rate/:item', component: HomesComponent},
    { path: 'details/:id/:name/:product', component: DetailComponent},
    ...
]
Run Code Online (Sandbox Code Playgroud)

根据客户的要求,我们需要更改两个组件的房屋路径。因此,我们更新了app.routing.module.ts。

更新了app.routing.module.ts

const routes: Routes = [
    { path: '', component: AComponent },
    ...
    { path: 'homes/:id/:rate/:item', component: HomesComponent},
    { path: 'homes/:id/:name/:product', component: DetailComponent},
    ...
]
Run Code Online (Sandbox Code Playgroud)

但是,由于我们在每个组件中使用的参数数量相同,因此会发生冲突,并且无法正确呈现,在所有情况下,它都路由到我们在“路由”列表中首先给出的HomesComponent。

你们有没有解决此问题的建议,而又不影响参数的路径和数量?

angular-routing angular angular5

1
推荐指数
1
解决办法
1188
查看次数