getx icon indicating copy to clipboard operation
getx copied to clipboard

setUrlStrategy in subfolder, error 404

Open aemsoftwarearacatuba opened this issue 1 year ago • 1 comments

Describe the bug when entering setUrlStrategy to remove the hashtag, and publishing the project within a subfolder: web/subfolder/, and when typing the route url, the 404 error always returns.

f the project is published on the web, the routes run perfectly. for this I am using , but when I enter , the 404 error occurs

https://docs.flutter.dev/ui/navigation/url-strategies

**Reproduction code

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  setUrlStrategy(PathUrlStrategy());

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Teste',
      initialRoute: '/',
      getPages: AppPages.pages,
    );
  }
}

abstract class AppPages {
  AppPages._();

  static final pages = <GetPage>[
    GetPage(
      name: '/',
      preventDuplicates: true,
      page: () => const Page1(
        title: 'Page 1',
      ),
      transition: Transition.fadeIn,
      transitionDuration: const Duration(milliseconds: 500),
    ),
    GetPage(
      name: '/page2',
      participatesInRootNavigator: true,
      preventDuplicates: true,
      page: () {
        final code = Get.parameters['code'] ?? '';

        return Page2(
          title: 'Page2',
          code: code,
        );
      },
      transition: Transition.fadeIn,
      transitionDuration: const Duration(milliseconds: 500),
    ),
    GetPage(
      name: '/page3',
      participatesInRootNavigator: true,
      preventDuplicates: true,
      page: () {
        return const Page3(
          title: 'Page3',
        );
      },
      transition: Transition.fadeIn,
      transitionDuration: const Duration(milliseconds: 500),
    ),
  ];
}

class Page1 extends StatefulWidget {
  const Page1({super.key, required this.title});
  final String title;

  @override
  State<Page1> createState() => _Page1State();
}

class _Page1State extends State<Page1> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Container(),
    );
  }
}

class Page2 extends StatefulWidget {
  const Page2({super.key, required this.title, required this.code});
  final String title;
  final String code;

  @override
  State<Page2> createState() => _Page2State();
}

class _Page2State extends State<Page2> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Text(widget.code),
      ),
    );
  }
}

class Page3 extends StatefulWidget {
  const Page3({super.key, required this.title});
  final String title;

  @override
  State<Page3> createState() => _Page3State();
}

class _Page3State extends State<Page3> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Container(),
    );
  }
}

To Reproduce Steps to reproduce the behavior:

  1. explain the project in a web subfolder.
  2. Run the project, and the home page will return successfully.
  3. type url/subfolder/page1 in the browser, and it will return 404 (File or directory not found.)

Expected behavior execute the route correctly, without using the hastag

Screenshots If applicable, add screenshots to help explain your problem.

Flutter Version: Flutter 3.19.2

Getx Version: get: ^4.6.6

Describe on which device you found the bug: Flutter web (chrome

Minimal reproduce code Provide a minimum reproduction code for the problem

aemsoftwarearacatuba avatar Mar 11 '24 13:03 aemsoftwarearacatuba

location / { try_files $uri $uri/ /index.html; }

2697a avatar Mar 19 '24 03:03 2697a