auto_route_library icon indicating copy to clipboard operation
auto_route_library copied to clipboard

browser refresh issue

Open kencana16 opened this issue 1 year ago • 2 comments

i have a web app that using path parameter inside route. the path param contain # character. it looks run as well, image

but when i trying to refresh web browser, the path is truncated at # char. image

from the capture above the URL is looks fine. but if we use usePathUrlStrategy(); URL also become to http://localhost:64319/#/seconds/123

note : for the prev version (I'm forget the version) this package make my url keep encoded(), and there is no issue when url is encoded. i also trying to encode param before navigate. but in url gonna decoded again

kencana16 avatar Dec 08 '23 13:12 kencana16

import 'package:auto_route/annotations.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';

import 'main.gr.dart';

void main() {
  
  runApp(MainApp());
}

class MainApp extends StatelessWidget {
  // make sure you don't initiate your router
  // inside of the build function.
  final _appRouter = AppRouter();

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: _appRouter.config(),
    );
  }
}

@AutoRouterConfig()
class AppRouter extends $AppRouter {
  @override
  List<AutoRoute> get routes => [
        AutoRoute(page: FirstRoute.page, initial: true),
        AutoRoute(page: SecondsRoute.page, path: "/seconds/:id"),
      ];
}

@RoutePage()
class FirstPage extends StatelessWidget {
  FirstPage({super.key});

  List<String> params = [
    "123#456#789",
    "123%23456%23789",
  ];

  @override
  Widget build(BuildContext context) {
    return Column(
      children: params
          .map((e) => Padding(
                padding: const EdgeInsets.all(16.0),
                child: ElevatedButton(
                    onPressed: () => context.pushRoute(SecondsRoute(
                          id: e,
                          query: e,
                        )),
                    child: Text(e)),
              ))
          .toList(),
    );
  }
}

@RoutePage()
class SecondsPage extends StatelessWidget {
  final String id;
  final String? query;
  const SecondsPage(
      {super.key, @PathParam() required this.id, @QueryParam() this.query});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        children: [
          Text("id :${id}"),
          Text("query :${query}"),
          Text("pathParam :${AutoRouter.of(context).current.pathParams}"),
          Text("queryparam :${AutoRouter.of(context).current.queryParams}"),
        ],
      ),
    );
  }
}

kencana16 avatar Dec 08 '23 13:12 kencana16

@Milad-Akarie. can i make my browser not auto decode the URL path/param after pages loaded?

kencana16 avatar Mar 05 '24 04:03 kencana16