【问题标题】:How to get Parameterized routes working如何让参数化路由工作
【发布时间】:2017-08-05 12:27:19
【问题描述】:

我可能只是遗漏了一些明显的东西,但我无法让 :id*id 工作。

这是我正在使用的路由配置:

{
  route: 'char/:id',
  name: 'char',
  moduleId: 'modules/char/char',
  href: "char"
}

这是我在char.ts中得到的代码:

export class Char {
  activate(params: {id: string}) {
    console.log(params.id);
  }
}

现在我似乎无法从地址栏中为id 赋值。 这个的语法是什么?

(我也尝试将参数设为可选,:id? 仍然没有)

【问题讨论】:

  • 你的路线很好如果你只有console.log(params)你有什么?是未定义的吗?
  • @maximedubois 不,它不会记录任何内容。如果我导航到http://localhost:9000/char 并将路由设置为'char/:id?,我将被重定向到主页。而如果我导航到 http://localhost:9000/char/ 我得到 404。如果我提供一个值 http://localhost:9000/char/?id=42 我在 vendor-bundle.js 脚本上得到一个 404。
  • @maximedubois nvm... 我是单页框架的新手,不知道我必须在 url 中的路由名称前加一个 #。谢谢任何:)

标签: routes aurelia url-parameters


【解决方案1】:

原来我从一开始就有点倒退了。
这是有效的:

http://localhost:9000/#char/foobar

那么id 将等于foobar

【讨论】:

    猜你喜欢
    • 2016-12-25
    • 2018-07-18
    • 2019-08-29
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 2023-03-15
    • 2018-10-23
    • 1970-01-01
    相关资源
    最近更新 更多