Period in query string parameter breaks Aurelia routes

守給你的承諾、 提交于 2021-01-29 04:35:47

问题


I'm trying to pass an e-mail address as a query string parameter to an Aurelia route.

The URL looks like: http://localhost/some/route?email=john@doe.com

However, it seems the dot (period) in the URL breaks the Aurelia route, resulting in a 404.

If I remove the dot, the route loads just fine.

Any ideas what's causing this? I'm surprised I can't find any information on it, having periods in a route should be fairly common?

Thanks!

Edit: Seems this may not be an Aurelia issue, but rather an ASP.NET MVC issue: Dots in URL causes 404 with ASP.NET mvc and IIS


回答1:


It seems to work fine with the basic setup like below. I've whipped this up together with the latest Aurelia CLI (v0.23). In this setup there are three files: the view (html), the viewmodel (ts) and the route (app.ts):

views/edit-dots.html

<template>
    <p>email: ${email}</p>
</template>

views/edit-dots.ts

export class EditDots {
    public email;

    activate(params: any) {
        console.log('here are *all* your parameters: ', params);
        this.email = params.email;
    }
}

And finally, the route config (in app.ts in my case):

import { Router, RouterConfiguration } from 'aurelia-router'

export class App {

    router: Router;

    configureRouter(config: RouterConfiguration, router: Router) {
    config.title = 'Stack';
    config.map([
        { route: ['', 'home'], name: 'home', moduleId: './views/home', nav: true, title: 'Home' },
        { route: 'dots/:id', name: 'edit-dots', moduleId: './views/edit-dots', nav: false, title: 'Create a dot' }
    ]);

    this.router = router;
    }
}

When I navigate to http://localhost:9001/#dots/42?email=harry@potter.com with this setup, it neatly displays the email address. Of course, I can remove the '42', it is just for demonstration purposes.

Final note, your example url doesn't seem to use the #-sign. If this is intentional, you might want to give some more details about your configuration. Otherwise, does it help adding it?

Perhaps this helps you as well?



来源:https://stackoverflow.com/questions/41342821/period-in-query-string-parameter-breaks-aurelia-routes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!